Automatizing web browser form filling in Python

百般思念 提交于 2021-02-17 14:50:47

问题


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.

Here is an image of what the survey looks like (CSS was disable for clarity). 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 HtmlUnit seems cool, if there were a comparable library in Python).
  • How to fill out form data on a website (question is about Java).

回答1:


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

  • Splinter - automate browser actions in Python

  • Mechanize - Python library for stateful programmatic web browsing

  • Selenium automizing framework Python bindings - using full installed browser

  • Headless web browsing listing - includes Python ones

  • Scrapy - web content scraping framework in Python

For installing Python packages please refer to official package installation tutorial.



来源:https://stackoverflow.com/questions/28932205/automatizing-web-browser-form-filling-in-python

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