控制使用Python浏览器? [英] Controlling Browser using Python?

查看:235
本文介绍了控制使用Python浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能控制使用Python如Firefox Web浏览器?

Is it possible to control a web browser like Firefox using Python?

我会想要做的事情一样。

I would want to do things like


  • 启动浏览器

  • 在网址,点击力

  • 采取截图

等。

推荐答案

硒的远程控制是非常接近你所追求的一个项目。这是很容易得到在Python工作使用随它 selenium.webdriver 子包。曾几何时,这些都是两个项目。现在他们已经被统一。

Selenium Remote Control is a project that comes very close to what you are after. It is really easy to get working in Python with the selenium.webdriver subpackage that comes with it. Once upon a time, these were two projects. They've now been unified.

简单!

$ pip install -U selenium

用法

>>> from selenium import webdriver
>>> ff = webdriver.Firefox()
>>> ff.get("http://stackoverflow.com/q/3369073/395287")
>>> ff.save_screenshot("/absolute/path/to/webpage.png')

注释

该文档可以稍微混乱的硒,因为有两种模式与浏览器的交互。还有的webdriver 模式下,很聊得来一个独立硒的远程控制服务器的能力。这种方法是在官方文件首次记录,但我会用的webdriver 坚守在这里简单的任务。

Notes

The documentation can be slightly confusing for Selenium, because there are two modes to interact with browsers. As well as the webdriver mode, there is the ability to talk to a "standalone Selenium Remote Control server". That approach is what is documented first in the official documentation, but I would stick with webdriver for the simple task here.

这篇关于控制使用Python浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆