簡體   English   中英

使用 Requests 庫登錄后如何獲取響應 cookie?

[英]How do I get the response cookie after logging with the Requests library?

我正在嘗試抓取網站以獲取我公司的運輸信息。 我能夠使用 Python 的請求庫登錄網站。 我面臨的問題是,在我登錄並嘗試導航到具有我需要的信息的其他 URL 后,cookie 發生更改並將我注銷。

當我在開發工具中查看網絡時,我看到它更改為的 cookie 是響應 cookie。 當我使用 cookies 查看它是否被拾取時,它只顯示請求 cookies。

我嘗試設置持久會話,但這沒有幫助。 然后我試着保存餅干,但一無所獲。 我不知道還能做什么。

url = 'http://website/login'
creds = {'_method':'****','username':'*****','password':'*****'}

response = requests.post(url,data=creds)
token = response.cookies
response = requests.get('http://webiste/reports/view/17',cookies=token)

你可以試試 token = response.headers['Set-Cookie']。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM