For help, php could not capture the webpage. I asked a few questions, but they didn't solve it.

Source: Internet
Author: User
For help, php could not crawl the webpage. I asked a few people to 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


Reply to discussion (solution)

You can first look at the html character entity


File_get_contents? Read the entire file into a string


Description

String file_get_contents (string $ filename [, bool $ use_include_path [, resource $ context [, int $ offset [, int $ maxlen])

Like file (), only file_get_contents () can read the file into a string. The content with the length of maxlen will be read at the position specified by the offset parameter. If it fails, file_get_contents () returns FALSE.

The file_get_contents () function is used to read the file content into a string. If the operating system supports it, the memory ing technology will be used to enhance the performance.


Note: If you want to open a URL with special characters (such as spaces), you need to use urlencode () for URL encoding.



In addition
'Header' => "> Accept-language: en/r/n"
What is the red part?
> Redundant./r/n should be \ r \ n.
If the header is incorrect, the server returns an error (505), which is normal.

File_get_contents? Read the entire file into a string


Description

String file_get_contents (string $ filename [, bool $ use_include_path [, resource $ context [, int $ offset [, int $ maxlen])

Like file (), only file_get_contents () can read the file into a string. The content with the length of maxlen will be read at the position specified by the offset parameter. If it fails, file_get_contents () returns FALSE.

The file_get_contents () function is used to read the file content into a string. If the operating system supports it, the memory ing technology will be used to enhance the performance.


Note: If you want to open a URL with special characters (such as spaces), you need to use urlencode () for URL encoding.



In addition
'Header' => "> Accept-language: en/r/n"
What is the red part?
> Redundant./r/n should be \ r \ n.
If the header is incorrect, the server returns an error (505), which is normal.

Data cannot be obtained after url encoding. the code is as follows:

$ Url = "http: // 110.75.65.8/search_turn_page_iphone.htm? Sort = & q = lizclaiborne & page = 1 & showMode = list "; echo Post (urlencode ($ 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 ));}

The actual error is: HTTP/1.1 505 HTTP Version Not Supported

File_get_contents (str_replace ('', '% 20', $ url ));

Now, it may have been a problem with his server.

$url="http://110.75.65.8/search_turn_page_iphone.htm?sort=&q=lizclaiborne&page=1&showMode=list";echo file_get_contents($url);
{"Result": "true", "totalPage": "100", "catmap": "", "ppath": "", "category ":"", "auctionTagFlag1": "", "auctionTagFlag2": "", "auctionTagFlag3": "", "listItem ":[
{"Name": "The United States genuine product liz claiborne Beauty Clay this women's wallet liz wallet", "img": "http://q.i02.wimg.taobao.com/bao/uploaded/i1/T18ZyyXfXgXXXc8SLa_122312.jpg_90x90.jpg", "img2": "http://q.i04.wimg.taobao.com/bao/uploaded/i1/T18ZyyXfXgXXXc8SLa_122312.jpg", "iswebp ": "", "url": "http://a.m.taobao.com/i2431550873.htm? Rn = bwHGEi1-ZClPeKBbGc1lfJhm45-D1gLR8O-pug7 & sid = 8b9c27255c655b1e "," previewUrl ":" http://a.m.taobao.com/ajax/pre_view.do? ItemId = 2431550873 & sid = 8b9c27255c655b1e "," favoriteUrl ":" http://fav.m.taobao.com/favorite/to_collection.htm? ItemNumId = 2431550873 & sid = 8b9c27255c655b1e ",
"Icon": ["0"],
"Price": "39.00", "originalPrice": "39.00", "freight": "10", "area": "Tianjin", "act ": "Monthly sale 1", "itemNumId": "2431550873", "nick": "Witch _ 2007 ",
..........

Well, the wrong data is stuck.
$ Url = "http: // 110.75.65.8/search_turn_page_iphone.htm? Sort = & q = liz claiborne & page = 1 & showMode = list ";
This does Not work. HTTP/1.1 505 HTTP Version Not Supported

This works.
$ Url = "http: // 110.75.65.8/search_turn_page_iphone.htm? Sort = & q = liz + claiborne & page = 1 & showMode = list ";
$ Url = "http: // 110.75.65.8/search_turn_page_iphone.htm? Sort = & q = liz % 20 claiborne & page = 1 & showMode = list ";

His server does not know what settings are made and does not accept url-encoded data.


Well, the wrong data is stuck.
$ Url = "http: // 110.75.65.8/search_turn_page_iphone.htm? Sort = & q = liz claiborne & page = 1 & showMode = list ";
This does Not work. HTTP/1.1 505 HTTP Version Not Supported

This works.
$ Url = "http: // 110.75.65.8/search_turn_page_iphone.htm? Sort = & q = liz + claiborne & page = 1 & showMode = list ";
$ Url = "http: // 110.75.65.8/search_turn_page_iphone.htm? Sort = & q = liz % 20 claiborne & page = 1 & showMode = list ";

His server does not know what settings are made and does not accept url-encoded data.

Can the server accept "data without url encoding?
What I understand is that the server can only accept url-encoded data,
If we open the address with spaces in the browser,
The browser has automatically encoded the url,
So open normally,
But php is not a browser,
So it will not automatically do these things,
Requires manual encoding,
Isn't that true?




Well, the wrong data is stuck.
$ Url = "http: // 110.75.65.8/search_turn_page_iphone.htm? Sort = & q = liz claiborne & page = 1 & showMode = list ";
This does Not work. HTTP/1.1 505 HTTP Version Not Supported

This works.
$ Url = "http: // 110.75.65.8/search_turn_page_iphone.htm? Sort = & q = liz + claiborne & page = 1 & showMode = list ";
$ Url = "http: // 110.75.65.8/search_turn_page_iphone.htm? Sort = & q = liz % 20 claiborne & page = 1 & showMode = list ";

His server does not know what settings are made and does not accept url-encoded data.

Can the server accept "data without url encoding?
What I understand is that the server can only accept url-encoded data,
If we open the address with spaces in the browser,
The browser has automatically encoded the url,
So open normally,
But php is not a browser,
So it will not automatically do these things,
Requires manual encoding,
Isn't that true?


The space character (\ x20) is a valid url character.
Once you have done an http socket, you will know that it is acceptable to send a url with spaces in the header.



Well, the wrong data is stuck.
$ Url = "http: // 110.75.65.8/search_turn_page_iphone.htm? Sort = & q = liz claiborne & page = 1 & showMode = list ";
This does Not work. HTTP/1.1 505 HTTP Version Not Supported

This works.
$ Url = "http: // 110.75.65.8/search_turn_page_iphone.htm? Sort = & q = liz + claiborne & page = 1 & showMode = list ";
$ Url = "http: // 110.75.65.8/search_turn_page_iphone.htm? Sort = & q = liz % 20 claiborne & page = 1 & showMode = list ";

His server does not know what settings are made and does not accept url-encoded data.

Can the server accept "data without url encoding?
What I understand is that the server can only accept url-encoded data,
If we open the address with spaces in the browser,
The browser has automatically encoded the url,
So open normally,
But php is not a browser,
So it will not automatically do these things,
Requires manual encoding,
Isn't that true?


The space character (\ x20) is a valid url character.
Once you have done an http socket, you will know that it is acceptable to send a url with spaces in the header.


That is to say, the query string is no matter what characters,
Can all servers receive them as they are?


The correct statement is as follows:
$ Url = "http: // 110.75.65.8/search_turn_page_iphone.htm? Sort = & q = ". urlencode ('Liz claiborne ')." & page = 1 & showMode = list ";




Well, the wrong data is stuck.
$ Url = "http: // 110.75.65.8/search_turn_page_iphone.htm? Sort = & q = liz claiborne & page = 1 & showMode = list ";
This does Not work. HTTP/1.1 505 HTTP Version Not Supported

This works.
$ Url = "http: // 110.75.65.8/search_turn_page_iphone.htm? Sort = & q = liz + claiborne & page = 1 & showMode = list ";
$ Url = "http: // 110.75.65.8/search_turn_page_iphone.htm? Sort = & q = liz % 20 claiborne & page = 1 & showMode = list ";

His server does not know what settings are made and does not accept url-encoded data.

Can the server accept "data without url encoding?
What I understand is that the server can only accept url-encoded data,
If we open the address with spaces in the browser,
The browser has automatically encoded the url,
So open normally,
But php is not a browser,
So it will not automatically do these things,
Requires manual encoding,
Isn't that true?


The space character (\ x20) is a valid url character.
Once you have done an http socket, you will know that it is acceptable to send a url with spaces in the header.


That is to say, the query string is no matter what characters,
Can all servers receive them as they are?



What do you think of line breaks and/breaks? of course they are not any character

This problem I have encountered before, take out "&" alone can say http://www.123.com? Id = 123 & num = 123;
Write $ url = 'http: // www.123.com? Id = 123 '. "&". 'Num = 123'; in this way, the compiler does not convert it into a string.

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.