求助php无法抓取网页,问了几个人都没解决
本帖最后由 dz215136304 于 2013-06-11 11:35:47 编辑
url必须为以下代码中的url,经测试,在抓取时,如果q后面的参数带空格,他会自动把"&"转换成"&",从而造成数据无法抓取,在网页中直接输入网址是可以得到内容的,求解决方法
<br />
$url="http://110.75.65.8/search_turn_page_iphone.htm?sort=&q=liz claiborne&page=1&showMode=list";<br />
echo Post($url);<br />
<br />
function Post($url, $post = null)//请求的网页<br />
{<br />
$context = array();<br />
<br />
if (is_array($post))<br />
{<br />
ksort($post);<br />
<br />
$context['http'] = array<br />
(<br />
<br />
'timeout'=>60,<br />
'method' => 'POST',<br />
'header'=>">Accept-language: en/r/n",<br />
'content' => http_build_query($post, '', '&'),<br />
);<br />
}<br />
<br />
return file_get_contents($url, false, stream_context_create($context));<br />
}<br />
Copier après la connexion
错误提示:
<br />
Warning: file_get_contents(http://110.75.65.8/search_turn_page_iphone.htm?sort=&q=liz claiborne&page=1&showMode=list) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: HTTP request failed! HTTP/1.1 505 HTTP Version Not Supported in F:\wwwroot\getTaobao\test.php on line 25<br />
Copier après la connexion