求助php无法抓取网页,问了几个人都没解决
本帖最后由 dz215136304 于 2013-06-11 11:35:47 编辑 url必须为以下代码中的url,经测试,在抓取时,如果q后面的参数带空格,他会自动把"&"转换成"&",从而造成数据无法抓取,在网页中直接输入网址是可以得到内容的,求解决方法
$url="http://110.75.65.8/search_turn_page_iphone.htm?sort=&q=liz claiborne&page=1&showMode=list";
echo Post($url);
function Post($url, $post = null)//请求的网页
{
$context = array();
if (is_array($post))
{
ksort($post);
$context['http'] = array
(
'timeout'=>60,
'method' => 'POST',
'header'=>">Accept-language: en/r/n",
'content' => http_build_query($post, '', '&'),
);
}
return file_get_contents($url, false, stream_context_create($context));
}
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