2017-06-10 112 views
-2

我是python和編程新手,非常感謝這裏的幫助。 我想使用下面的代碼登錄到this網站,我只是不能超越第一頁。Python - 難以登錄網站

下面是我一直在努力的代碼...

import requests 
from bs4 import BeautifulSoup 
response = requests.get('https://www.dell.com/sts/passive/commercial/v1/us/en/19/Premier/Login/Anonymous?wa=wsignin1.0&wtrealm=http%253a%252f%252fwww.dell.com&wreply=https%253a%252f%252fwww.dell.com%252fidentity%252fv2%252fRedirect') 

soup = BeautifulSoup(response.text) 
formtoken = soup.find('input', {'name': '__RequestVerificationToken'}).get('value') 

payload = {'UserName' = username, 'Password'=password, '__RequestVerificationToken': formtoken} 
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0'} 
with requests.Session() as s: 
    p = s.post('https://www.dell.com/sts/passive/commercial/v1/us/en/19/Premier/Login/Anonymous?wa=wsignin1.0&wtrealm=http%253a%252f%252fwww.dell.com&wreply=https%253a%252f%252fwww.dell.com%252fidentity%252fv2%252fRedirect', data=payload, headers=headers) 
    r = s.get('http://www.dell.com/account/', headers=headers) 
    print r.text 

我只是無法超越的登錄頁面。除登錄外還有什麼參數。我也嘗試檢查Chrome開發工具中的表單數據,但它是加密的。 Form Data - Dev Tool screenshot

任何幫助這裏是高度讚賞。

編輯 我已經編輯了代碼,在有效載荷中傳遞令牌,如下所示。但我還沒有運氣。

回答

0

您沒有按照正確的方法進行POST請求。

步驟,你可以遵循:

  1. 首先要與你的URL的GET請求。
  2. 從響應中提取訪問令牌。
  3. 爲您的發佈請求使用該訪問令牌。
+0

謝謝您的回覆。我在你提出建議後就這樣做了,但無濟於事。 – taz22