CURL pt. 2

Hey everybody,

Great night last night...thanks!

Here is that CURL code I talked about:

If you find you could use a hand with it, fire me off an email. <?
ob_start();
ob_end_flush();
include "db.inc.php";
$domain = "http://www.cafepress.com/nooiltv";
$userAgent = "No Oil(www.nooil.tv)";
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$domain);
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);
$Gstore = curl_exec ($ch);
if (curl_errno($ch))
{
print curl_error($ch);
}else{
$info = curl_getinfo($ch);
curl_close($ch);
$dom = new DOMDocument();
@$dom->loadHTML($Gstore);
$xpath = new DOMXPath($dom);
$spans = $xpath->evaluate("/html/body//img");
for ($ii = 0; $ii < $spans->length; $ii++)
{
$Span = $spans->item($ii);
$span = $Span->getAttribute('src');
if(preg_match('#/product/#',$span))
{
$isql="INSERT INTO cafepress_images VALUES('".$span."')";
mysql_query($isql);
// print $span;
// print "\n";
}
}
}
?>

No votes yet

Comments

embedding code in a post

Thanks for that Eric!  Just a note for everyone... if you are wondering how to embed code in a post like Eric did here

put it between code tags as follows:

"<code>

[your code here]

</code>"

It will probably work better if you use plain text format as well.

Bob Snodgrass

Bob Snodgrass