I've been thinking about the difference between the content and the Text property of requests, which is no different from the print results.
Importrequestsheaders= { "user-agent":"mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) applewebkit/537.36 (khtml, like Gecko) chrome/65.0.3325.181 safari/537.36"}url='https://www.sogou.com/web?query={}'Key= Input ('Please enter') Params= {'Query': Key}response= Requests.get (url,params=params,headers=headers)Print(Response.text)
The conclusion is that text returns a Unicode type of data, typically a coded form defined in the header of a Web page.
The content returned is bytes, the second-class data.
Which means if you want to extract the text, use text.
But if you want to extract pictures and files, you need content.
#1. Import the Requests module ImportRequests#2. Send Request for Binary data (bytes)Respone = Requests.get ("http://imgsrc.baidu.com/image/c0%3Dpixel_huitu%2C0%2C0%2C294%2C40/sign=098c3f828cd6277ffd1f3a7841407a5c/ 3c6d55fbb2fb4316e3afd1432ba4462309f7d353.jpg") #get binary data; Note: Here do not decode, because pictures, videos and other files are binary not text, do not need to decode #data = Respone.content #3. Writing data to a fileWith open ("wallpapers. jpg","WB") as F:f.write (respone.content)
The difference between crawler content and text in Python