填写在线表格 [英] Fill out online form
问题描述
我正在尝试使用用户名和密码填写位于 https://idp.ncedcloud.org/idp/AuthnEngine#/authn
的表单。我想知道是否成功通过。我试过它ith python2,但我无法让它工作。
I'm trying to fill out the form located at https://idp.ncedcloud.org/idp/AuthnEngine#/authn
with a username and password. I want to know if went through successfully or not. I tried it ith python2, but I couldn't get it to work.
#!/usr/bin/env python
import urllib
import urllib2
name = "username"
name2 = "password"
data = {
"description" : name,
"ember501": name2
}
encoded_data = urllib.urlencode(data)
content = urllib2.urlopen("https://idp.ncedcloud.org/idp/AuthnEngine#/authn",
encoded_data)
print(content)
错误:
它打印同一网页的内容,我希望它打印新的网页内容。
所需行为:
python3解决方案进入下一个网页,或者为什么我的代码无效
error:
It prints the content of the same webpage, and I want it to print the new webpage content.
desired behavior:
python3 solution that goes to the next webpage, or why my code isn't working
推荐答案
使用请求图书馆。我建议使用会话,以便为以下任何请求保存您的登录信息:
Basic example of posting data to a webpage like this using requests library. I would suggest using session, so that your login info is saved for any following requests:
import requests
url = "http://example.com"
name = "username"
name2 = "password"
data = {
"description" : name,
"ember501": name2
}
s = requests.Session()
# If it supports basic auth you could just do
# s.auth(username, password) here before a request
req = s.post(url, data=data)
print(req.text)
然后应该可以使用 s $ c $执行以下请求c>会话对象
Should then be able to do following requests with the s
session object
这篇关于填写在线表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!