Use Fsockopen to get Baidu search page

Source: Internet
Author: User
I use PHP functions such as fsockopen and Fwrite,fgets command can directly get http://www.baidu.com home content, but can not get http://www.baidu.com/s?wd= speaker &pn= 20 content, very depressed, think Baidu did a precaution, but it is strange that I will all the browser cache and cookies are removed, directly with the address bar to access the http://www.baidu.com/s?wd= speaker &pn=20, but can directly obtain the content, But with PHP functions to get, but how can not. How can Baidu distinguish between browser access and program Access? Who can tell the reason and the guidance of the next maze.
I have no more points, the money to buy PHP solution is OK


Reply to discussion (solution)

Add useragent to try,
Reference: http://tuzwu.iteye.com/blog/723260

Of course, we've tried it, and we've done a full imitation with reference to Fiddler2 intercepted data.

I think there's something wrong with your network.

Character Set coding problem?

Odd strange, with file_get_contents really feasible, but with my method is only Baidu can not get, other URLs are successful, this is why?

Character set encoding no problem, I've tried it over and over again, the same code, file_get_contents is okay.

I don't know how you wrote it.

$fp = Fsockopen ("www.baidu.com", $errno, $errstr,) $out = "Get/s?wd= speaker &pn=20 http/1.1\r\n"; $out. = "Host:www. Baidu.com\r\n "; $out. =" connection:close\r\n\r\n "; fwrite ($fp, $out); while (!feof ($fp)) {  echo fgets ($FP, 128);} Fclose ($FP);
This time, no stickers, a piece of data.
Resource ID #2HTTP/1.1 OK
Date:fri, 07:21:48 GMT
server:bws/1.0
content-length:109229
Content-type:text/html;charset=utf-8
Cache-control:private
Bdpagetype:3
bduserid:0
bdqid:0xba09dfbd018d026b
set-cookie:bdsvrtm=245; path=/
set-cookie:h_ps_pssid=4316_1462_4181_4261; path=/; Domain=.baidu.com
set-cookie:baiduid=93a4febc6a24e74b727fee7001e65b50:fg=1; Expires=fri, 29-nov-43 07:21:47 GMT; path=/; Domain=.baidu.com
p3p:cp= "OTI DSP COR IVA our IND COM"
Connection:close

......

> SpeakerChannel SpeakerQuote Center brand Rover BOSE Mabowill JBL Philips Lida Logitech Mi novo Innovation Lang Qin more >> price 100 yuan under 101-200 yuan 201-300 yuan 301-500 yuan 501-800 yuan ... speaker.pcpop.com/soundbox/2013-11-11 -target= "_blank"
class= "M" > Baidu Snapshot See more about " Speaker Channel"Content >>

Data-click= "{
' F ': ' 778317EA ',
' F1 ': ' 9d73f1e4 ',
' F2 ': ' 4ca6dd6b ',
' F3 ': ' 54e5243f ',
' T ': ' 1385709708 ',
' Y ': ' F3d2fedf '

}"
href= "Http://www.baidu.com/link?url=iHdhI9m-N3i0M6QsBp8zjalqAtClICWD28BH_hXsPvRlaAAlSHQ9pzL0AZsRgan2"

target= "_blank"

> Speaker -Computer Speaker _ Audio -it168 Speaker Channel

IT168SpeakerChannel to provide you with the most professional and authoritativeSpeaker、AudioProduct reviews to bring you the latest and most accurateSpeaker、AudioProduct information Quotation information, to provide you with a variety of gradesSpeakerAndAudioProduct analysis, to help you better buy ...sound.it168.com/2013-11-15

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.