Php cannot crawl web pages. I asked a few questions but they didn't solve the problem.

Source: Internet
Author: User
For help with php, the webpage cannot be crawled. I asked a few people who did not solve this issue. In the end, the url edited by dz215136304 at 2013-06-11:35:47 must be the url in the following code. after testing, if the parameter after q contains spaces, it will automatically convert & amp; into & amp;, which makes the data unable to be captured, you can directly enter the URL on the webpage to obtain the content. the solution is as follows: $ for help, php cannot crawl the webpage. I asked a few questions and I didn't solve the problem.

This post was last edited by dz215136304 at 11:35:47

The url must be the url in the following code. after testing, if the parameter after q is captured with spaces, it will automatically convert "&" "&", as a result, the data cannot be captured. you can enter the URL directly on the webpage to obtain the content.

$ 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) // requested webpage
{
$ 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 ));
}


Error message:

Warning: file_get_contents(http://110.75.65.8/search_turn_page_iphone.htm?sort=&q=liz claiborne&page=1&showMode=list) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 505 HTTP Version Not Supported in F:\wwwroot\getTaobao\test.php on line 25

Share:


------ Solution --------------------
Urlencode () after Transcoding ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.