使用 Python 自动填写 Web 浏览器表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28932205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Automatizing web browser form filling in Python
提问by Josh Desmond
Question:
题:
Hi. I am a beginner trying to learn Python, and for one of my first projects I want to write a script that will fill out a survey automatically for me. I am familiar with coding, and I have most of the code written to solve this problem. What I am struggling is to write a method that will hit button #1 in question #1, or that will push any given button. One way I've realized I can do this, is perhaps by writing a script to press tab-> up-> down-> tab-> up -> down in the order needed to answer all of the questions.
你好。我是一个试图学习 Python 的初学者,对于我的第一个项目,我想编写一个脚本,该脚本将自动为我填写一份调查问卷。我熟悉编码,并且我编写了大部分代码来解决这个问题。我正在努力编写一个方法,可以在问题 #1 中点击按钮 #1,或者按下任何给定的按钮。我意识到我可以做到这一点的一种方法,也许是编写一个脚本,按照回答所有问题所需的顺序按 tab-> up-> down-> tab-> up -> down。
Here is an image of what the survey looks like (CSS was disable for clarity). http://i.imgur.com/Tn94KFA.jpg
这是调查的图像(为了清晰起见,禁用了 CSS)。 http://i.imgur.com/Tn94KFA.jpg
What is one way to go about writing a method to push a radio button?
编写按下单选按钮的方法的一种方法是什么?
[Disclaimer]: I have checked out the following questions but they were of no use to me in my current situation:
[免责声明]:我已经检查了以下问题,但在我目前的情况下它们对我没有用:
- fill out a webform that uses javascript with python(question was framed very strangely and was about Javascript forums, which I don't understand how it is relevant/ I didn't understand it, and nobody answered the question).
- Script to take web survey for me(answers were only about Java, however something like this tool called HtmlUnitseems cool, if there were a comparable library in Python).
- How to fill out form data on a website(question is about Java).
- 填写一个使用 javascript 和 python 的网络表单(问题的框架非常奇怪并且是关于 Javascript 论坛的,我不明白它是如何相关的/我不明白它,没有人回答这个问题)。
- 为我进行网络调查的脚本(答案仅与 Java 有关,但是,如果 Python 中有类似的库,那么类似名为 HtmlUnit 的工具似乎很酷)。
- 如何在网站上填写表单数据(问题是关于 Java)。
采纳答案by Mikko Ohtamaa
There are Python libraries and tools for automatizing browser actions. StackOverflow.com is not a place to ask for an recommendation for such a tool and thus moderators will close this question (SO is usually asking a help for particular problem, not for broad help and tutoriing requests). However here are some starting points for you
有用于自动化浏览器操作的 Python 库和工具。StackOverflow.com 不是要求推荐此类工具的地方,因此版主将关闭此问题(SO 通常是针对特定问题寻求帮助,而不是针对广泛的帮助和辅导请求)。但是这里有一些起点
Mechanize - Python library for stateful programmatic web browsing
Selenium automizing framework Python bindings- using full installed browser
Selenium 自动化框架 Python 绑定- 使用完整安装的浏览器
For installing Python packages please refer to official package installation tutorial.