Home  >  Article  >  Backend Development  >  php-curl采集百度搜索结果没有图片

php-curl采集百度搜索结果没有图片

WBOY
WBOYOriginal
2016-06-02 11:28:18908browse

phpcurl

<code><?php $url = "http://www.baidu.com/s?wd=csdn";// 构造包头,模拟浏览器请求$header = array (        "Host:www.baidu.com",        "Content-Type:application/x-www-form-urlencoded",//post请求        "Connection: keep-alive",        'Referer:http://www.baidu.com',        'User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; BIDUBrowser 2.6)');$ch = curl_init ();curl_setopt ( $ch, CURLOPT_URL, $url );curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header );curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );// 执行$content = curl_exec ( $ch );if ($content == FALSE) {    echo "error:" . curl_error ( $ch );}// 关闭curl_close ( $ch );//输出结果echo $content;?></code>

图片说明

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn