簡體   English   中英

Python請求登錄網站

[英]Python Requests Logging into a website

Heyo,

能夠使用請求和.post方法登錄我的學校網站(嘗試創建顯示新結果的提要)

url = "https://pipeline.tsc.nsw.edu.au/scots/pages/main/login.php"
payload = {'username': 'my.name', 'password': 'password'}

with requests.Session() as s:
    r = s.post(url, data=payload)
    print(r.text) # Write to file and create filter to check against old code

我遇到的困難是該網站似乎在瀏覽器欄中為您生成一個帶有“ eduId”的URL

https://pipeline.tsc.nsw.edu.au/scots/pages/mainframe.php?eduId=3993834&displayID=&theme=scots&version=4.2.2&demo=-1

成功登錄該站點后,您將重定向到該URL,但我似乎無法通過請求獲得它。

有人知道如何處理重定向或收集重定向的URL嗎? 謝謝

注意:我可以告訴您登錄未發生或未注冊重定向,因為下載的代碼中未顯示錯誤的登錄消息

我建議您看看Mechanize python庫,Mechanize的行為類似於瀏覽器,並使其更易於處理會話,重定向等。http://wwwsearch.sourceforge.net/mechanize/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM