Home > Backend Development > PHP Tutorial > php无法抓取网页,问了几个人都没解决

php无法抓取网页,问了几个人都没解决

WBOY
Release: 2016-06-13 12:41:10
Original
896 people have browsed it

求助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 />
Copy after login


错误提示:
<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 />
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template