anks Posted July 10, 2011 Share Posted July 10, 2011 Folks, Been 2 days, still trying to figure out how to get around this. I need to extract the webpage content in a PHP variable. http://affiliates.beso.com/product-search/content?publisherId=27085&categoryId=&keyword=furniture-entertainment-center&showDesc=imageDescriptionText&col=4&row=4&placementid=2&minMarkdown=0&w=140&h=160\ Till now, i have used CURL, fopen, file_get_contents() but all in vain. there is no Output written to the Variable ($prodlist). Could some one help me with this requirement, Please? :-\ Quote Link to comment https://forums.phpfreaks.com/topic/241570-how-to-get-webpage-contnet-in-a-variable/ Share on other sites More sharing options...
spfoonnewb Posted July 10, 2011 Share Posted July 10, 2011 cURL can definitely do this. Look into CURLOPT_RETURNTRANSFER. Quote Link to comment https://forums.phpfreaks.com/topic/241570-how-to-get-webpage-contnet-in-a-variable/#findComment-1240822 Share on other sites More sharing options...
anks Posted July 10, 2011 Author Share Posted July 10, 2011 Ok as you suggested, here is my CURL: <?php function curl_download($Url){ // is cURL installed yet? if (!function_exists('curl_init')){ die('Sorry cURL is not installed!'); } // OK cool - then let's create a new cURL resource handle $ch = curl_init(); // Now set some options (most are optional) // Set URL to download curl_setopt($ch, CURLOPT_URL, $Url); // Set a referer //curl_setopt($ch, CURLOPT_REFERER, "http://www.google.com/yay.htm"); // User agent curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0"); // Include header in result? (0 = yes, 1 = no) curl_setopt($ch, CURLOPT_HEADER, 0); // Should cURL return or print out the data? (true = return, false = print) curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Timeout in seconds curl_setopt($ch, CURLOPT_TIMEOUT, 10); // Download the given URL, and return output $output = curl_exec($ch); // Close the cURL resource, and free system resources curl_close($ch); return $output; } $url = "http://affiliates.beso.com/product-search/content?publisherId=57085&categoryId=&keyword=paintball%20mask&showDesc=imageDescriptionText&col=4&row=4&placementid=1&minMarkdown=0&w=140&h=160"; $szlcontent = curl_download($url); echo $szlcontent; ?> Returns NOthing. At the same time, This URL has Products still CURL not able to Dump in a Variable... :-\ http://affiliates.beso.com/product-search/content?publisherId=57085&categoryId=&keyword=paintball%20mask&showDesc=imageDescriptionText&col=4&row=4&placementid=1&minMarkdown=0&w=140&h=160 Any Help Please? Quote Link to comment https://forums.phpfreaks.com/topic/241570-how-to-get-webpage-contnet-in-a-variable/#findComment-1240839 Share on other sites More sharing options...
wildteen88 Posted July 10, 2011 Share Posted July 10, 2011 Your curl script is working. The problem is that the url http://affiliates.beso.com/product-search/content?publisherId=57085&categoryId=&keyword=paintball%20mask&showDesc=imageDescriptionText&col=4&row=4&placementid=1&minMarkdown=0&w=140&h=160 Is only returning this html code <?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xml:lang="en" lang="en"> <head> <link rel="stylesheet" type="text/css" href="http://img13.beso-images.com/s2static/us/pb/6706a675/local/css/common/product_gallery.css"/> <script type="text/javascript" src="http://img13.beso-images.com/s2static/us/pb/6706a675/local/js/widget/content.js"> </script> <script type="text/javascript" src="http://img13.beso-images.com/s2static/us/pb/6706a675/local/js/widget/util.js"> </script> </head> <body onload="BesoWidget.searchForProducts();" id="iframe-body"> <form name="config"> <input id="sho.publisherId" type="hidden" value="25225"> </input> <input id="sho.apiKey" type="hidden" value="638b348a826889501ea9d18d8984ab44"> </input> <input id="sho.serverTimeout" type="hidden" value="5000"> </input> <input id="sho.serverUrl" type="hidden" value="http://catalog.bizrate.com"> </input> <input id="sz.assetid" type="hidden" value="2795"> </input> </form> </body> </html> The list of products appears to be being listed dynamically using JavaScript. Quote Link to comment https://forums.phpfreaks.com/topic/241570-how-to-get-webpage-contnet-in-a-variable/#findComment-1240864 Share on other sites More sharing options...
IrOnMaSk Posted July 11, 2011 Share Posted July 11, 2011 hey Anks, may I ask whose webpage that is? lol ... and what do you want to do after you store the page inside a variable? I have similare problem and able to solved this this way $file = file_get_contents ('path to webpage', true); If that doesn't work, write the webpage content to file first, then open it and do the file get content, this will definitly work... let me know Quote Link to comment https://forums.phpfreaks.com/topic/241570-how-to-get-webpage-contnet-in-a-variable/#findComment-1241562 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.