我想用php采集一个网站的数据,但是无法获取该网站的数据。网址如下:
http://www.alldatasheet.com/view.jsp?searchword=78hc
希望您能试一下,只要能返回数据就行了。我试了很久不能成功。
回复讨论(解决方案) $header = array ( get /view.jsp?searchword=78hc http/1.1,host: www.alldatasheet.com,connection: keep-alive,cache-control: max-age=0,accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,user-agent: mozilla/5.0 (windows nt 6.1) applewebkit/537.22 (khtml, like gecko) chrome/25.0.1364.152 safari/537.22,accept-encoding: gzip,deflate,sdch,accept-language: en-us,zh-cn;q=0.8,zh;q=0.6,accept-charset: utf-8,*;q=0.5,cookie: jsessionid=bd1418bc3f4ca9084f0c022a98687a09; track_id=117.25.173.111363310326444; seekstr=*78h*..; seekshot=78h..1..75..8..112; __utma=191189370.2036196682.1363308553.1363308553.1363308553.1; __utmb=191189370.3.10.1363308553; __utmc=191189370; __utmz=191189370.1363308553.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); arp_scroll_position=900); // 初始化一个 curl 对象$curl = curl_init(); // 设置你需要抓取的urlcurl_setopt($curl, curlopt_url, 'http://www.alldatasheet.com/view.jsp?searchword=78hc');curl_setopt($curl, curlopt_httpheader, $header); //设置header // 设置header显示方式curl_setopt($curl, curlopt_header, 0); // 设置curl 参数,要求结果保存到字符串中还是输出到屏幕上。curl_setopt($curl, curlopt_returntransfer, 1); // 运行curl,请求网页$data = curl_exec($curl); // 关闭url请求curl_close($curl); // 显示获得的数据var_dump($data);
只要是浏览器能访问的页面,应该都能采集的。
关键是cookie。
