-1
我已經經歷了無數Google結果和堆棧溢出問題,試圖找出如何執行以下操作。大多數人建議使用請求會話類來存儲會話信息。如何使用Python的請求正確登錄到網站?
不幸的是,沒有提供的解決方案與我嘗試過的任何網站一起工作。很明顯,我做錯了一些事情,我想弄清楚自己瘋狂之前是什麼。
我當前的代碼:
from requests import session
from bs4 import BeautifulSoup as bs
USER = 'leinad177'
PASSWORD = '' # removed for obvious reasons
URL = 'https://en.wikipedia.org/w/index.php?title=Special:UserLogin'
with session() as s:
login_data = {'wpName': USER,
'wpPassword': PASSWORD}
r = s.post(URL, data=login_data)
r = s.get('https://en.wikipedia.org/wiki/Special:Preferences')
print bs(r.text).find('div', {'id':'mw-content-text'}).p.text.strip()
# "Please log in to change your preferences."
你能夠進入更多關於檢索wpLoginToken的細節嗎? – Leinad177
我編輯了我的帖子並添加了如何獲取令牌。 –
非常完美,非常感謝。 – Leinad177