Skip to content

Instantly share code, notes, and snippets.

@pingyen
Created March 17, 2015 15:01
Show Gist options
  • Select an option

  • Save pingyen/e52453514b65804148e4 to your computer and use it in GitHub Desktop.

Select an option

Save pingyen/e52453514b65804148e4 to your computer and use it in GitHub Desktop.
Crawling Google
<?php
$q = 'demo';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.google.com.tw/search?q=' . rawurlencode($q) . '&tbm=nws&tbs=qdr:d');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.91 Safari/537.36');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec($ch);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment