Jump to content

curl help


darkfreaks

Recommended Posts

can i do something like this? but how would i make it grab just the cheapest price and the server and return it?

 

$target_url = "http://www.bankofwow.com/cart.php?target=category&category_id=7873";
$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';

// make the cURL request to $target_url
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
#curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$html= curl_exec($ch);
if (!$html) {
    echo "<br />cURL error number:" .curl_errno($ch);
    echo "<br />cURL error:" . curl_error($ch);
    exit;
}

// parse the html into a DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($html);

// grab all the on the page
$xpath = new DOMXPath($dom);

 

 

Link to comment
https://forums.phpfreaks.com/topic/199737-curl-help/#findComment-1048352
Share on other sites

This right here will get the pages source

 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.bankofwow.com/cart.php?target=category&category_id=7873');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
$results = curl_exec ($ch);

 

now I'm still a little nooby when it comes to string manipulation cause i don't use it often but this is the method i would use because i find it very easy to understand

 

$tempname = explode(' class="SidebarItems">',$results);
for ($i = 1; $i < sizeof($tempname); $i++) {
$name = explode('</FONT></a></td>',$tempname[$i]);
$names[$i] = $name[0];
}

 

What I'm basically doing there is splitting the page by the information in the source that is constant and comes before the name there are other methods of doing this. but this is the way i understand it.

 

Link to comment
https://forums.phpfreaks.com/topic/199737-curl-help/#findComment-1048374
Share on other sites

We I perform the curl request I get a bunch of jibberish returned. If I could get the html I'm sure I could parse it to get what you want.

 

Here's what I am seeing

‹í=ërÚÈÒ¿×Uy‡‰rÛµw;†ÆNì=vÌYWΩ-j€I«‹Y6›úÞòëž];ö&9eg×FBÓÓÓÓÝÓÝÓÓ:|¾·Gþ;`Íøìí5žmžö.Îá/|âßM_4ñïÅI¯I¦®kí±?<í¦®´LÃe†»×[XL!CqUW\ö§››º3ý5N©í0·®9æ^­VÞßSÑIï¬w~ÒhA7¹º¼"ïL}”!üš9np‹&›Ì†AN>t.ÉiêºF!;Ì ØŒ¹”tÆêÊ5[ÌM{äDÐòNææœL¢²ÔdÄœ¡ Y®f‘VqÔHWsYöŠ‘)½aIJTÛ¶6dNöÈ[„÷ƦMºTgd®¹SÞn€mfßÀÄðu\¼7bºvÃìöBuÇ$–mÞh#FÆ6c¢—

 

 

Link to comment
https://forums.phpfreaks.com/topic/199737-curl-help/#findComment-1048742
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.