一、requests的get操作:
import requests data={"wd":"关晓彤"} headers={"User-Agent" : "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36 QIHU 360SE"} #header 字典形式 url="https://www.baidu.com/s?" req=requests.get(url,params=data,headers=headers) print(req.text)
二、requests的post操作:
import requests #data为flddler抓包登录的 POST 尾部数据 在flddler的 TextView 显示 data={"emp_no":"1admin","password":"admin"} headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"} #/index.php?m=&c=public&a=check_login flddler上Headers查看POST的后缀 url="http://demo.smeoa.com/index.php?m=&c=public&a=check_login" req=requests.post(url, data=data,headers=headers) print(req.text)
三、requests的ssl操作:
import requests import json #verify 证书 req=requests.get("https://www.12306.cn",verify=True) #默认用证书,不安全会报错; verify=False,不会报错 print(req)
四、requests的cookie操作:
import requests import time mycookie=dict(BDSID="zhadu") req=requests.get("http://httpbin.org/cookies",cookies=mycookie) time.sleep(3) print(req.cookies) print(req.text)