0
我是python請求的新手,我正在使用它來刮取網站並訪問某個網頁,首先我登錄,然後再爲其他網頁做幾個請求:如何在使用python請求時在多個請求中使用相同的cookie
import requests
url1 = 'https://ringzer0team.com/login'
s = requests.Session()
request = s.get(url1)
print s.cookies
print request.cookies
request = s.post(url1, auth=('username', 'password'))
print request.cookies
url2 = 'https://ringzer0team.com/home'
request = s.get(url2, cookies = s.cookies)
print request.cookies
url3 = 'https://ringzer0team.com/challenges'
request = s.get(url3, cookies = s.cookies)
print request.cookies
url4 = 'https://ringzer0team.com/challenges/13'
request = s.get(url3, cookies = s.cookies)
print request.cookies
我相信這是因爲Cookie獲取會話過程中丟失,這裏是輸出我得到:
正如你所看到的,cookie丟失後,我發表我的憑據url1和我可以得到url的內容2但不是那些url3和url4。 s.cookies始終保持不變,所以我一直試圖在所有獲取請求中使用它,但沒有取得任何成功。任何幫助,將不勝感激。