点击(此处)折叠或打开
- import requests
- # 登录后才能访问的网页
- url = 'http://www.baidu.com'
- # 浏览器登录后得到的cookie,也就是刚才复制的字符串
- cookie_str = r'key1=ualue1; key2=value2'
- # 把cookie字符串处理成字典,以便接下来使用python
- cookies = {}
- for line in cookie_str.split(';'):
- key, value = line.split('=', 1)
- cookies[key] = value
- # 设置请求头
- headers = {
- 'User-agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36'}
- # 在发送get请求时带上请求头和cookies
- for i in range(10000):
- requests.get(url, headers=headers, cookies=cookies).text