fill out a webform that uses javascript with python

两盒软妹~` 提交于 2019-12-25 18:19:42

问题


i am trying to fill out a webform using a python program by submitting specific values. the problem is it uses javascript. i will post an example of the value i want to fill.

fo.addVariable("email","email@yahoo.com")
fo.addVariable("age","19")
fo.addVariable("gender","M")
fo.addVariable("line","hello")

that is an example of the value on the page. what i want to do is submit a value to that and change it. what i am currently attempting is this:

data = urllib.parse.urlencode({"line": "hello", "age": "50", "email":  "email@yahoo.com", "gender": "M"}).encode()
resp = urlreq.urlopen("http://url.com/update", data) 

this usually works for most webforms. but for this one it will not.


回答1:


In python 2.7, urllib has no attribute urllib.parse and a .encode() function at the end is unnecessary.

I think what you should be writing is

data = urllib.urlencode({"line": "hello", "age": "50", "email":  "email@yahoo.com", "gender": "M"})


来源:https://stackoverflow.com/questions/16128552/fill-out-a-webform-that-uses-javascript-with-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!