我試圖從受用戶名和密碼保護的網頁檢索信息。如何跳過無聲登錄?
我通過身份驗證,發送POST與我的用戶名和密碼。之後,我回到重定向頁面的響應對象。當我瀏覽該頁面時,我發現我必須等待幾秒鐘或點擊繼續進入主頁面。我的問題是如何跳過此重定向或強制腳本轉到主頁面。
import requests
main_url = 'https://my_main_page.com/edit#'
login = {
'USER' : 'username',
'PASSWORD' : 'password',
}
r = requests.post(main_url,
data=login,) #here I have now redirecting page with the
#url as main_url , but in page source I see
#redirecting page, not my expected page
print r.url
print r.text
它不起作用:/,如果我設置allow_redirect = False,我的腳本不響應。在我的網絡瀏覽器中,如果我登錄,我會收到一條消息,告訴我幾秒鐘後,我將被重定向到主頁面。它可能需要一秒鐘,我在主頁上。腳本如何做到這一點? :/ –
你想要轉到主頁面嗎?如果你想要它,請嘗試allow_redirects = True。告訴我,如果它的工作 – arodriguezdonaire
它也行不通。我想我需要創建會話,但我不知道如何。 –