View Full Version : Fetching data from webpage based on elements ID/Class

17 Apr 2011, 07:23 AM
Hi, I'm searching for a way or an existing API/function that does the following:

I want to give this function a URL and an ID/Class,
the function will return an array of the HTML/Text content of
the HTML elements that possess these attributes.

Where do I even start with this thing?

18 Apr 2011, 10:33 AM
look at cURL in PHP


$url = "www.mysite.com"; // change to suit
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec($ch);
echo $html; // $html contains the page, in HTML, which you have scraped

You will need to process the $html variable to fish out what you want and output it to the page.