1 import requests 2 kw = {'wd':"中国"} 3 headers = { 4 "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36" 5 } 6 resp = requests.get('http://www.baidu.com/s',params=kw, headers=headers) 7 print(type(resp.content))#返回的源代码以二进制储存 8 print(type(resp.text))#将上面的数据自行解码后的数据,但是经常会出现乱码,一般自行解码 9 print(resp.content.decode('utf-8')) 10 print(resp.url)#返回网址 11 print(resp.encoding)#返回编码方式 12 print(resp.status_code)#响应状态码
1 import requests 2 import json 3 4 5 headers = { 6 "User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36", 7 "Referer":"https://www.lagou.com/jobs/list_python?labelWords=&fromSearch=true&suginput=" 8 } 9 data = { 10 "first":"true", 11 "pn":1, 12 "kd":"python" 13 } 14 resp = requests.post("https://www.lagou.com/jobs/list_python?labelWords=&fromSearch=true&suginput=",data=data,headers=headers) 15 print(resp.text)