我使用python来抓取我学校的网页,但是为了做到这一点,我需要先模拟用户登录。这是我的代码:
import requests, lxml.html
s = requests.session()
url = "https://my.emich.edu"
login = s.get(url)
login_html = lxml.html.fromstring(login.text)
hidden_inputs = login_html.xpath(r'//form//input[@type="hidden"]')
form = {x.attrib["name"]:x.attrib["value"] for x in hidden_inputs}
form["username"] = "myusernamge"
form["password"] = "mypassword"
form["submit"] = "LOGIN"
response = s.post("https://netid.emich.edu/cas/loginservice=https%3A%2F%2Fmy.emich.edu%2Fc%2Fportal%2Flogin",form)
response = s.get("http://my.emich.edu")
f = open("result.html","w")
f.write(response.text)
print response.text
我正期待着呢响应.text会给我自己的学生帐户页,而不是它给我一个登录要求页。有人能帮我解决这个问题吗? 顺便说一句,这不是家庭作业
这里有几个选项,我认为您的请求方法可以通过手动登录和复制头来简化。在
另外,你需要请求登录主页(再次)后,你成功地做了帖子。在
相关问题 更多 >
编程相关推荐