graham23s Posted December 5, 2008 Share Posted December 5, 2008 Hi Guys, I was wondering what the best way to parse the html from a webpage recovered by curl? $go = curl_exec($c); kinda thing, any advice would be great cheers Graham Quote Link to comment https://forums.phpfreaks.com/topic/135684-best-way-to-parse-webpage-using-curl/ Share on other sites More sharing options...
gevans Posted December 5, 2008 Share Posted December 5, 2008 I've never needed to use curl myself, but, obvious resource php.net's example is; <?php // create a new cURL resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, "http://www.example.com/"); curl_setopt($ch, CURLOPT_HEADER, 0); // grab URL and pass it to the browser curl_exec($ch); // close cURL resource, and free up system resources curl_close($ch); ?> What more were you hoping to do with regards to parsing? Quote Link to comment https://forums.phpfreaks.com/topic/135684-best-way-to-parse-webpage-using-curl/#findComment-706952 Share on other sites More sharing options...
graham23s Posted December 5, 2008 Author Share Posted December 5, 2008 Hi Mate, it was more in the regards to parsing the html code of: http://www.example.com/ so i could preg_match the parts i needed to get. thanks mate Graham Quote Link to comment https://forums.phpfreaks.com/topic/135684-best-way-to-parse-webpage-using-curl/#findComment-706983 Share on other sites More sharing options...
gevans Posted December 5, 2008 Share Posted December 5, 2008 OK, from what I can tell, to get the page content into a string simply; <?php // create a new cURL resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, "http://www.example.com/"); curl_setopt($ch, CURLOPT_HEADER, 0); // grab URL and pass it to the browser $data = curl_exec($ch); // close cURL resource, and free up system resources curl_close($ch); //Then you can use $data for parsing ?> Forgive me if I'm not giving you great answers, learning curl as I go along, lol Quote Link to comment https://forums.phpfreaks.com/topic/135684-best-way-to-parse-webpage-using-curl/#findComment-706993 Share on other sites More sharing options...
premiso Posted December 5, 2008 Share Posted December 5, 2008 If you dont have curl a slower function is file_get_contents That tends to work, just about 1-2 seconds slower, but the call is much easier <?php $html = file_get_contents('http://www.example.com'); //now all the html is the $html ?> =) Quote Link to comment https://forums.phpfreaks.com/topic/135684-best-way-to-parse-webpage-using-curl/#findComment-707014 Share on other sites More sharing options...
Maq Posted December 5, 2008 Share Posted December 5, 2008 Hi Guys, I was wondering what the best way to parse the html from a webpage recovered by curl? $go = curl_exec($c); kinda thing, any advice would be great cheers Graham Back to your original question, after you grab the contents just utilize regex, substrings, etc. to grab what you need. You need to figure out the structure of how they display their content first. You may want to look up something similar to screen scraping. Quote Link to comment https://forums.phpfreaks.com/topic/135684-best-way-to-parse-webpage-using-curl/#findComment-707016 Share on other sites More sharing options...
kanoameha Posted February 25, 2011 Share Posted February 25, 2011 once you get the curl results you will need to replace a bunch of stuff to get the page to work. use parse_url and then do a regex or replace and fix all relative references. If they stay relative then the links will try to reference data on YOUR site instead of data on THEIR site. Quote Link to comment https://forums.phpfreaks.com/topic/135684-best-way-to-parse-webpage-using-curl/#findComment-1179334 Share on other sites More sharing options...
Maq Posted February 25, 2011 Share Posted February 25, 2011 I understand you have good intentions, but please don't resurrect a thread that's over 2 years old. Quote Link to comment https://forums.phpfreaks.com/topic/135684-best-way-to-parse-webpage-using-curl/#findComment-1179573 Share on other sites More sharing options...
cunoodle2 Posted February 25, 2011 Share Posted February 25, 2011 Why does this thread have over 4,200 views?? Quote Link to comment https://forums.phpfreaks.com/topic/135684-best-way-to-parse-webpage-using-curl/#findComment-1179686 Share on other sites More sharing options...
Maq Posted February 25, 2011 Share Posted February 25, 2011 Why does this thread have over 4,200 views?? Because it was posted: December 05, 2008, 01:09:27 PM Quote Link to comment https://forums.phpfreaks.com/topic/135684-best-way-to-parse-webpage-using-curl/#findComment-1179699 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.