1. session对象可以自动处理cookies
import requests
def make_session(debug=False):
s = requests.session()
s.verify = False
s.trust_env = False
s.headers = {
'Connection': 'keep-alive',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh;q=0.9',
}
if debug:
s.proxies = {
'http': '127.0.0.1:8888',
'https': '127.0.0.1:8888',
}
return s
如果debug设为True,则使用端口号为8888的charles抓包