抓取百度搜索结果

来源:互联网 发布:sql substr函数 编辑:程序博客网 时间:2024/04/23 21:41

抓取百度搜索结果,但是用file_get_content会出现false
后来找到一个函数

function curlPost($url, $data=array(), $timeout = 30){    // $interface = "eth0:" . rand(1, 4); //避免GG封IP    // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);    // $cookie_file = dirname(__FILE__) . "/temp/google.txt"; //存储cookie值    $ch = curl_init();    curl_setopt($ch, CURLOPT_URL, $url);    // curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);//获取浏览器类型    // curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5");    // curl_setopt($ch, CURLOPT_INTERFACE, "$interface"); //指定访问IP地址    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);    // curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);    $contents = curl_exec($ch);    curl_close($ch);    return $contents;}

用这个函数就可以(没注释),后来想弄明白到底是需要哪一项,于是就注释成了上面的样子,还是ok的,是因为cookie?

0 0
原创粉丝点击