Python:使用 urllib 或 urllib2 单击按钮
我想用python点击一个按钮,表单的信息由网页自动填充。用于向按钮发送请求的 HTML 代码是:
INPUT type="submit" value="Place a Bid">
我将如何执行此操作? 是否可以仅使用 urllib 或 urllib2 单击按钮?或者我需要使用机械化或斜纹布之类的东西吗?
I want to click a button with python, the info for the form is automatically filled by the webpage. the HTML code for sending a request to the button is:
INPUT type="submit" value="Place a Bid">
How would I go about doing this?
Is it possible to click the button with just urllib or urllib2? Or will I need to use something like mechanize or twill?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用表单目标并将任何输入作为发布数据发送,如下所示:
Python:
您可以使用 HTMLParser 解析 HTML
并且不要忘记使用以下方式对任何帖子数据进行 urlencode:
urllib.urlencode(查询)
Use the form target and send any input as post data like this:
Python:
You can parse the HTML with HTMLParser
And don't forget to urlencode any post data with:
urllib.urlencode(query)
您可能需要查看 IronWatin - https://github.com/rtyler/IronWatin 来填充表单并使用代码“单击”按钮。
You may want to take a look at IronWatin - https://github.com/rtyler/IronWatin to fill the form and "click" the button using code.
使用 urllib.urlopen,您可以将表单的值作为数据参数发送到表单标记中指定的页面。但这不会为您自动化您的浏览器,因此您必须首先以其他方式获取表单值。
Using urllib.urlopen, you could send the values of the form as the data parameter to the page specified in the form tag. But this won't automate your browser for you, so you'd have to get the form values some other way first.