简体   繁体   English

无法登录我的学校网站

[英]Cannot login to my school website

I am trying to use a python script (specifically requests) for logging into my university account and having the program do what I need it to do. 我正在尝试使用python脚本(特别是请求)登录我的大学帐户并让程序执行我需要它做的事情。 I used the following code to try logging into the website: 我使用以下代码尝试登录网站:

import requests
import time

url = 'https://myschool.edu/'

next_url = 'https://mynextpage.edu/'
login_data = {"j_username":'input username here', "j_password":'input password here'}


with requests.Session() as s:
    s.get(url)
    p = s.post(url, data=login_data)
    # print the html returned or something more intelligent to see if it's a successful login page.
    print p.text
    time.sleep(40)

    # An authorised request.
    r = s.get(next_url)
    print r.text

When I have p.text print out, all I see is the html to the original login page. 当我打印出p.text时,我看到的只是原始登录页面的html。 I don't understand what I am typing wrong about this. 我不明白我输错了什么。 Thanks for all your help!! 感谢你的帮助!!

  1. Goes with http://selenium-python.readthedocs.io/ , and let the browser handle most of the heavy liftings. http://selenium-python.readthedocs.io/一起使用 ,让浏览器处理大部分繁重的工作。
  2. If you indeed want to interact with the server directly in Python, you may end up dealing with session/cookie/credential kind of stuff, which could be a hassle. 如果你确实想直接用Python与服务器进行交互,你最终可能会处理会话/ cookie /凭证类的东西,这可能很麻烦。

1 feels like programming while 2 is more like hacking. 1感觉像编程,而2更像是黑客攻击。 ;) ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM