填写一个使用 javascript 和 python 的网络表单
问题描述:
我正在尝试通过提交特定值使用 python 程序填写网络表单.问题是它使用javascript.我将发布一个我想要填充的值的示例.
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.
答
在 python 2.7 中,urllib 没有属性 urllib.parse 并且末尾的 .encode() 函数是不必要的.
In python 2.7, urllib has no attribute urllib.parse and a .encode() function at the end is unnecessary.
我认为你应该写的是
data = urllib.urlencode({"line": "hello", "age": "50", "email": "email@yahoo.com", "gender": "M"})