本文介绍了填写一个使用 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"})

这篇关于填写一个使用 javascript 和 python 的网络表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 23:17