import requests
def getCookie(url):
session = requests.Session()
headers = {
'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'
}
session.get(url, headers=headers)
# 获取当前的Cookie
Cookie = dict(session.cookies)
CookieString=''
for key in Cookie.keys():
if CookieString != '':
CookieString += '; '
CookieString += key + "=" + Cookie[key]
return CookieString
print(getCookie('https://www.baidu.com'))