[英]python requests library redirect new page to post request
我是python的新手,我必須檢索此頁面的數據。 http://mims.com/india/drug/search?q=dextro,但是由於該網站需要用戶登錄,因此我經歷了以下代碼。
import requests
from bs4 import BeautifulSoup as bs
POST_LOGIN_URL = "https://sso.mims.com/Account/Signin"
REQUEST_URL = "https://mims.com/india/drug/search?q=DEXTRO%20PLUS"
payload = {
"EmailAddress": "email address here",
"Password" : "password here"
}
with requests.Session() as session:
post = session.post(POST_LOGIN_URL, data=payload)
r = session.get(REQUEST_URL)
with open('abc.html', 'wb')as f:
f.write(r.content)
它沒有將期望的結果顯示出來,而是將我重定向到頁面,並且我收到一個“ FORM”元素,其中包含method =“ post”請求和一個自動單擊的按鈕。 因此,我無法弄清楚,請有人幫助。
使用Selenium Webdriver解決了該問題,並在登錄或任何其他GET請求后等待 。
這樣后台請求就完成了執行並返回到所需的頁面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.