I'm attempting to send a CURL request and then use 'simple_html_dom
' class to find the html elements I want. (Parsing) — in this case I send a CURL request to 'google.com' and then use 'simple_html_dom
' class to select all of the links of the page. (or any other HTML tags.)
The problem:
I don't know how to combine CURL with the 'simple_html_dom
' class.
Here is my code:
Curl Request:
function GetPage($url){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, true);
$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';
curl_setopt($curl, CURLOPT_USERAGENT, $userAgent);
$str = curl_exec($curl);
curl_close($curl);
return $str;
}
$output = GetPage('http://www.google.com/');
How I attempt to use 'simple_html_dom
' class:
$html = new simple_html_dom();
$html->load($output, true, false);
$links = $html->find('a');
foreach ($links as $link){
echo $link.'</br>';
}
When I load my file, it shows no errors, but it doesn't show the links I selected either.
Note:
I've looked through this website to make sure this question hasn't been answered,but it actually was answered a couple of times, but it still didn't solve it.