Python之requests请求,获取cookies,Requests带cookies爬取

requests请求,获取cookies,Requests带cookies爬取

 

import requests
from urllib.parse import urljoin

BASE_URL = 'https://login2.scrape.center/'
LOGIN_URL = urljoin(BASE_URL, '/login')
INDEX_URL = urljoin(BASE_URL, '/page/1')
USERNAME = 'admin'
PASSWORD = 'admin'

response_login = requests.post(LOGIN_URL, data={
   'username': USERNAME,
   'password': PASSWORD
}, allow_redirects=False)

cookies = response_login.cookies
print('Cookies', cookies)

response_index = requests.get(INDEX_URL, cookies=cookies)
print('Response Status', response_index.status_code)
print('Response URL', response_index.url)

 

 

来自拉勾教育 52讲轻松搞定网络爬虫

 

posted @ 2021-08-24 10:08  宝山方圆  阅读(1210)  评论(0编辑  收藏  举报