WORK@HOME
Senior Member
- Apr 25, 2013
- 1,013
- 479
Hey guys.I have this section of code I can't get to work to scraoe google search results.I need help to make this work big time.
Any help will be awesome.
Any help will be awesome.
Code:
function get_google($kw, $res=10, $geo='US') {
$urls = array();
if ($geo == '') $geo = 'US';
$url = 'http://www.google.com/search?hl=en&as_qdr=all&gl='.$geo.'&q='.urlencode($kw).'&num='.$res;
try {
$html = curl_fetch($url);
$dom = new DOMDocument();
@$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");
for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);
if ($href->getAttribute('class') == 'l') {
$link = explode('?', $href->getAttribute('href'));
$urls[] = $link[0];
}
}
} catch (Exception $e) {}
return $urls;
}