使用robobrowser提交aspnetForm时出现问题

时间:2019-05-29 16:52:46

标签: python asp.net selenium web-scraping robobrowser

我需要登录并在此.aspx网站上做进一步的剪贴,我尝试为此使用robobrowser,但这不起作用。

正确填写了表单,因为它正确返回了表单。 输出:

the form before filling....................
<RoboForm __VIEWSTATE=/wEPDwUJNzA0MDQwNTMxD2QWAmYPZBYCAgMPZBYEAgcPZBYEAgMPZBYCZg9kFgICAQ8QZGQWAWZkAgcPZBYCZg9kFgICAQ9kFgICBA9kFgJmD2QWAgIBD2QWAmYPZBYCAgEPZBYEZg9kFgJmD2QWAgIBD2QWAmYPZBYCAgEPEA8WBh4NRGF0YVRleHRGaWVsZAUHRmluWWVhch4ORGF0YVZhbHVlRmllbGQFCUZpblllYXJJRB4LXyFEYXRhQm91bmRnZBAVDwotLVNlbGVjdC0tCjIwMTktMjAyMCAKMjAxOC0yMDE5IAoyMDE3LTIwMTggCjIwMTYtMjAxNyAKMjAxNS0yMDE2IAoyMDE0LTIwMTUgCjIwMTMtMjAxNCAKMjAxMi0yMDEzIAoyMDExLTIwMTIgCjIwMTAtMjAxMSAKMjAwOS0yMDEwIAoyMDA4LTIwMDkgCjIwMDctMjAwOCAKMjAwNi0yMDA3IBUPATACMTQCMTMCMTICMTECMTABOQE4ATcBNgE1ATQBMwEyATEUKwMPZ2dnZ2dnZ2dnZ2dnZ2dnFgECAWQCAQ9kFgJmD2QWAgIBD2QWAmYPZBYCAgEPEGRkFgBkAgkPDxYCHgRUZXh0BQsyNi1GZWItMjAxOWRkZKQz4nMKFr7mh0FDINEDmSGJVOtHPJSQ+dGbUkOwx0zX, __EVENTVALIDATION=/wEdAAe5Y5Bk8Hb/9tDCCekTz6/XM53Y8ZOLfkHDcm83dIGbmLHg4zuDo887rMmdulsCaAPs0I8Mn+YPuHswTYNssJXEp/pWXPESmd1Dqvn9V8rW2UNZqwSuQEoekfVzh/C83DCcH2gR0XzlUqPs/zaB71jf1dift0o+ISWdbTsoA8LMe2leDW9ux4hgCyWTDjtUUjQ=, ctl00$cph1$rdbtnlType=1, ctl00$cph1$txtUsernm=, ctl00$cph1$txtPassword=, ctl00$cph1$btnLogin=Login >>>
the form after filling the data...................
<RoboForm __VIEWSTATE=/wEPDwUJNzA0MDQwNTMxD2QWAmYPZBYCAgMPZBYEAgcPZBYEAgMPZBYCZg9kFgICAQ8QZGQWAWZkAgcPZBYCZg9kFgICAQ9kFgICBA9kFgJmD2QWAgIBD2QWAmYPZBYCAgEPZBYEZg9kFgJmD2QWAgIBD2QWAmYPZBYCAgEPEA8WBh4NRGF0YVRleHRGaWVsZAUHRmluWWVhch4ORGF0YVZhbHVlRmllbGQFCUZpblllYXJJRB4LXyFEYXRhQm91bmRnZBAVDwotLVNlbGVjdC0tCjIwMTktMjAyMCAKMjAxOC0yMDE5IAoyMDE3LTIwMTggCjIwMTYtMjAxNyAKMjAxNS0yMDE2IAoyMDE0LTIwMTUgCjIwMTMtMjAxNCAKMjAxMi0yMDEzIAoyMDExLTIwMTIgCjIwMTAtMjAxMSAKMjAwOS0yMDEwIAoyMDA4LTIwMDkgCjIwMDctMjAwOCAKMjAwNi0yMDA3IBUPATACMTQCMTMCMTICMTECMTABOQE4ATcBNgE1ATQBMwEyATEUKwMPZ2dnZ2dnZ2dnZ2dnZ2dnFgECAWQCAQ9kFgJmD2QWAgIBD2QWAmYPZBYCAgEPEGRkFgBkAgkPDxYCHgRUZXh0BQsyNi1GZWItMjAxOWRkZKQz4nMKFr7mh0FDINEDmSGJVOtHPJSQ+dGbUkOwx0zX, __EVENTVALIDATION=/wEdAAe5Y5Bk8Hb/9tDCCekTz6/XM53Y8ZOLfkHDcm83dIGbmLHg4zuDo887rMmdulsCaAPs0I8Mn+YPuHswTYNssJXEp/pWXPESmd1Dqvn9V8rW2UNZqwSuQEoekfVzh/C83DCcH2gR0XzlUqPs/zaB71jf1dift0o+ISWdbTsoA8LMe2leDW9ux4hgCyWTDjtUUjQ=, ctl00$cph1$rdbtnlType=2, ctl00$cph1$txtUsernm=username, ctl00$cph1$txtPassword=password, ctl00$cph1$btnLogin=Login >>>
http://103.85.92.197/Accsoft2/Login.aspx
<Response [200]>

这是我使用的代码

from robobrowser import RoboBrowser
print("//////////////////////////")
url = 'http://103.85.92.197/Accsoft2/Login.aspx'
login_url = url

username = "username"
password = "password"

browser = RoboBrowser(history=True)
# This retrieves __VIEWSTATE and friends
browser.open(login_url)

form = browser.get_form()
print("the form before filling....................")
print(form)
form["ctl00$cph1$txtUsernm"].value = username
form["ctl00$cph1$txtPassword"].value = password
form["ctl00$cph1$rdbtnlType"].value = "2"
print("the form after filling the data...................")
print(form)
browser.submit_form(form)
print (browser.url) 
print(browser.response)
#print(browser.parsed)

从输出中可以看到,即使响应为200(确定),我仍然在同一页面上。 提交表单或单击登录按钮的任何更好的方法。避免使用Selenium,因为该脚本将被添加到kivy应用程序中。松散,漂亮的汤或机械化的任何帮助都可以。

0 个答案:

没有答案