1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#!/usr/local/php/bin/php <?php $keyword = '黄晓敏'; //关键词 $pageNum = 10; //每页显示几个 $page = '1'; //第几页 $lang = 'com'; //针对哪个国家的搜索结果 $all = ''; //保存结果 $query = urlencode($keyword); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://www.google.' . $lang . '/search?oe=utf8&num=' . $pageNum . '&ie=utf8&source=uds&start='. $pageNum * ($page - 1).'&hl=en&q='. $query); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); $content = urldecode(htmlspecialchars_decode(curl_exec($ch))); preg_match_all('/<h3 class=\"r\"><a href=\"\/url\?q=(.*?)&sa=/', $content, $matchs); foreach($matchs[1] as $http) { $all .= $http. "\n"; } //file_put_contents('1', $all); echo $all; curl_close($ch); |