chrome远程调试器接口。

ChromeController的Python项目详细描述


chrome远程控制接口和调试协议及工具包。Build StatusCoverage Status

注意:由于上游chromium错误,测试当前已中断:https://bugs.chromium.org/p/chromium/issues/detail?id=849972

使用google chrome和/或python chrome的一站式服务。你的色度控制器 完全访问从javascript获得的整个调试接口,但使用的语言 不会让人想去当牧羊人。

流程生命周期管理、选项卡管理,以及完整的chrome远程调试 接口通过python公开。

通过解析远程调试协议自动生成代码来自动更新 描述JSON文件。

快速启动:

importChromeControllerwithChromeController.ChromeContext(binary="google-chrome")ascr:# Do a blocking navigate to a URL, and get the page content as served by the remote# server, with no modification by local javascript (if applicable)raw_source=cr.blocking_navigate_and_get_source("http://www.google.com")# Since the page is now rendered by the blocking navigate, we can# get the page source after any javascript has modified it.rendered_source=cr.get_rendered_page_source()# We can get the current browser URL, after any redirects.current_url=cr.get_current_url()# We can get the page title as the browser sees it.page_title,page_url=cr.get_page_url_title()# Or take a screenshot# The screenshot is the size of the remote browser's configured viewport,# which by default is set to 1024 * 1366. This size can be changed via the# Emulation_setVisibleSize(width, height) function if needed.png_bytestring=cr.take_screeshot()# We can spoof user-agent headers:new_headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.79 Safari/537.36,gzip(gfe)','Accept-Language':'en-us, en;q=1.0,fr-ca, fr;q=0.5,pt-br, pt;q=0.5,es;q=0.5','Accept':'image/png,  text/plain;q=0.8, text/html;q=0.9, application/xhtml+xml, application/xml, */*;q=0.1','Accept-Encoding':'gzip,deflate',}cr.update_headers(new_headers)# We can extract the cookies from the remote browser.# This call returns a list of python http.cookiejar.Cookie cookie# objects (the Chrome cookies are converted to python cookies).cookie_list=cr.get_cookies()# We can also set cookies in the remote browser.# Again, this interacts with http.cookiejar.Cookie() objects# directly.cook=http.cookiejar.Cookie(<params>)cr.set_cookie(cook)# We can create more tabs in the current browser context.# Note that these additional tabs are scoped to the same lifetime as the original # chromium object (`cr`), so they will become invalid after leaving the # ChromeContext() context manager.tab_2=cr.new_tab()tab_3=cr.new_tab()# At this time, multiple tabs are not thread safe, so they *probably* shouldn't # be accessed concurrently. This *is* something that I'd like to change.

这个库广泛使用pythonlogging框架,并将日志记录到 日志路径。

通过解析为远程接口自动创建包装类 chromeprotocol.json文件,以及通过动态 阿斯特大楼。虽然这不是最容易维护的设计,但我选择了它 因为我想要一个学习/试验python ast操作的借口。

在自动生成的基础上实现了更高层次的自动化层 包装纸。高级接口及其相关文档都是 目前正在进行中。

接口文档在这里:
https://fake-name.github.io/ChromeController/ChromeController.ChromeRemoteDebugInterface.html

所有远程方法都包装在命名函数中,并进行(部分)验证 传递的参数类型和返回类型。 现在,简单参数类型验证已经完成(例如,文本参数必须是 对于string类型,数值参数必须是int或float等)。 但是,复合类型参数(基本上,任何接受数组的 或对象)由于正确构造的复杂性而未被验证。 给定体系结构的语义类型验证器(读:编写 原始AST中的验证器打断了我的大脑)。

主要在Python3.5、3.6上进行测试,在3.4和3.7上进行测试,全部在Linux上进行。如果你是 使用Python2,请停止。它可以在普通铬和窗户上使用, 但这只是很容易使用的。我的测试目标是 谷歌提供了chrome二进制文件。

注意,这个工具直接生成和操作ast,因此 对实现细节极其敏感。可能是坏了 python>;3.7或<;3.4。

传输层(最初)来自https://github.com/minektur/chrome_remote_shell

库还有一个相对有用的cli接口,主要用于 执行诸如获取包含jerberscript呈现内容的页面的操作:

 python3 -m ChromeController --help
Usage: __main__.py [OPTIONS] COMMAND [ARGS]...

  ChromeController

  Usage: python3 -m ChromeController [-s | --silent] [-v | --verbose]
    python3 -m ChromeController fetch <url> [--binary <bin_name>] [--outfile <out_file_name>]
    python3 -m ChromeController update
    python3 -m ChromeController (-h | --help)
    python3 -m ChromeController --version

  Options:
    -s --silent   Suppress all output aside from the fetched content
                  This basically makes ChromeController act like a alternative to curl
    -v --verbose  The opposite of silent. Causes the internal logging to output
                  all traffic over the chromium control interface. VERY noisy.
    --version     Show version.
    fetch         Fetch a specified URL's content, and output it to the console.


Options:
  -v, --verbose  The opposite of silent. Causes the internal logging to output
                 all traffic over the chromium control interface. VERY noisy.
  -s, --silent   Suppress all output aside from the fetched content.
                 This can be used to make ChromeController act like
                 an alternative to curl with proper JS rendering.
  --help         Show this message and exit.

Commands:
  fetch    Fetch a specified URL's content, and output...
  update   Update the generated class
  version  Print the ChromeController Version

许可证: bsd


目前的用法基本上是在 Chromium远程调试接口:

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java数据结构和算法实现字典   java RecyclerView执行项目单击   php解析数据组织时出错。json。JSONException:值<!java类型的DOCTYPE。无法将lang.String转换为JSONObject(Android)   java无法修复ArrayIndexOutOfBoundsException   是否可以将java转换为java。util。Date()到int?   java J2ME本机Mp3播放器,用于播放大于1.5 MB的Mp3文件   java如何在JAXWS web服务上抛出自定义错误?   在Graphstream中检索鼠标单击的图形   java Servlet不显示来自数据库的图像   使用Jackson框架的@RequestBody注释的java Spring引导ObjectMapper   web服务如何查看为Java程序生成的SOAP请求和响应   java打印出三维数组并得到组合的整数值   使用ExtentReports打印Arraylist时发生java错误   java如何在历史日期运行oozie?   java LIBGDX:SpriteBatch draw未在iOS上绘制   java如何将两个具有一些公共实体的不同JSON转换为pojo?   java JPA/Hibernate试图在具有复合Id(和双重属性)的实体中存储太多参数   java如何使用@Resource注册bean