用于自动浏览的工具集
autobrowser的Python项目详细描述
autobrowser的目标是在第三方模块的帮助下提供工具,允许用户使用web浏览器以编程方式浏览web。 它特别有助于从没有api的网站中识别和访问内容。
依赖关系
- 网络浏览器(最好是Firefox)
- python 2.7版
- 龙卷风
- 硒
功能
- 探测:
- 通过用户在web浏览器中的html元素上的mousedown事件帮助识别html元素及其在dom树中的确切css位置。 标识的html元素将有一个特定的属性集,该属性集将保存在提供的文件中,并由插入符号(^)
- 执行循环:
- 接受用户函数并可以以单线程顺序方式或多进程周期方式重复运行它
安装
$ pip install autobrowser
用法
- 用于在Web浏览器中探测HTML元素
- 请确保仅使用调用的浏览器中的默认活动选项卡进行探测。
- 在开始探测之前,请让浏览器完全加载网页。
fromseleniumimportwebdriverfromautobrowserimportprobewd=webdriver.Firefox()probe.Probe(wd,<path/to/ssl_privatekey_file>,<path/to/ssl_certificate_file>,<activity_output_file>).start()
示例输出
event^datetime^elem_location^elem_id^elem_tagName^elem_className^elem_innerHTML^css_location mousedown^2015-01-01T12:41:00.691Z^www.google.com.hk/^lst-ib^INPUT^gsfi lst-d-f^^BODY>DIV:nth-child(1)>DIV:nth-child(5)>FORM:nth-child(3)>DIV:nth-child(2)>DIV:nth-child(2)>DIV:nth-child(1)>DIV:nth-child(1)>DIV:nth-child(1)>DIV:nth-child(1)>DIV:nth-child(2)>DIV:nth-child(1)>INPUT:nth-child(1) mousedown^2015-01-01T12:41:05.202Z^www.google.com.hk/^^INPUT^^^BODY>DIV:nth-child(1)>DIV:nth-child(5)>FORM:nth-child(3)>DIV:nth-child(2)>DIV:nth-child(3)>CENTER:nth-child(1)>INPUT:nth-child(1) mousedown^2015-01-01T12:41:09.108Z^www.google.com.hk/^^A^^Giant panda - Wikipedia, the free encyclopedia^BODY>DIV:nth-child(1)>DIV:nth-child(7)>DIV:nth-child(3)>DIV:nth-child(7)>DIV:nth-child(2)>DIV:nth-child(3)>DIV:nth-child(1)>DIV:nth-child(2)>DIV:nth-child(2)>DIV:nth-child(2)>DIV:nth-child(2)>OL:nth-child(1)>DIV:nth-child(6)>LI:nth-child(1)>DIV:nth-child(1)>H3:nth-child(1)>A:nth-child(1) mousedown^2015-01-01T12:41:13.397Z^en.wikipedia.org/wiki/Giant_panda^^SPAN^^Giant panda^BODY>DIV:nth-child(3)>H1:nth-child(4)>SPAN:nth-child(1)
- 用于在执行循环中运行函数
fromautobrowserimportutilityfromseleniumimportwebdriverfromselenium.webdriver.common.keysimportKeyswd=webdriver.Firefox()deffoo():wd.get("http://google.com")# you can use the css_location retrieved from the autobrowser Probe in the css selectorelem=wd.find_element_by_css_selector("BODY>DIV:nth-child(1)>DIV:nth-child(5)>FORM:nth-child(3)>DIV:nth-child(2)>DIV:nth-child(2)>DIV:nth-child(1)>DIV:nth-child(1)>DIV:nth-child(1)>DIV:nth-child(1)>DIV:nth-child(2)>DIV:nth-child(1)>INPUT:nth-child(1)")elem.send_keys("cricket")elem.send_keys(Keys.RETURN)# For running repeatedly in sequential manner with '60' seconds delayutility.FunctionRunner(foo).repeat_sequential(60)# For running repeatedly in periodic manner every '15' seconds# with 5 processes## utility.FunctionRunner(foo).repeat_periodic(15, 5)
许可证
麻省理工学院的执照
版权所有(c)2014 Sagar Nilesh Shah
兹免费准许任何人取得副本 本软件和相关文档文件(“软件”)的 在软件中不受限制,包括但不限于 使用、复制、修改、合并、发布、分发、再授权和/或出售 软件的副本,并允许软件的用户 在满足以下条件的情况下,可以这样做:
上述版权公告及本许可公告须包括在 软件的所有副本或大部分。
本软件按“原样”提供,无任何形式的保证,明示或 默示的,包括但不限于适销性保证, 适合特定目的和不侵权。在任何情况下 作者或版权所有者应对任何索赔、损害或其他 责任,无论是在合同诉讼、侵权诉讼或其他诉讼中, 不属于或与软件、使用或其他交易有关 软件。