用python编写的JS控制台

jsConsole的Python项目详细描述


JS控制台

为python编写的JavaScript控制台

什么是jsConsole?

JavaScript让你可以像在python控制台中那样使用JavaScript控件!在

用法

只要从模块中导入所有内容,就可以开始了!在

>>>fromjsConsoleimport*#### And now you can use classes like document, window, Math or console from Python!>>>console.log('jsConsole is ready!')'jsConsole is ready!'>>>window.open('https://google.com','_self')# Opens google.com on the browser #>>>defhello():...print('Hello')...>>>document.getElementsByClassName('RNNXgb')[0].addEventListener('click',hello)### Adding an event listener to the search bar from google.com which executes hello() when clicked.>>>window.kill()# Needed to kill the browser (for it not to stay in the background even with Python quited)

安装

用PyPI(pip)Python依赖项/模块管理器安装它。在

^{pr2}$

浏览器配置

默认情况下,jsConsole使用运行在Chromium上的pyppeeer来执行JavaScript。在

您可以配置要与jsConsole.internal.config一起使用的浏览器

>>>importjsConsole.internal.configasjsConsoleConfig>>>jsConsoleConfig.layer# defines the layer (Selenium of Pyppeteer) you want to use --> String>>>jsConsoleConfig.executable_path# Sets the executable path of the browser you want to use. --> String>>>jsConsoleConfig.no_sandbox# Sets wether you want to use the --no-sandbox argument whie opening the browser or not (useful for Linux) --> bool>>>jsConsoleConfig.args# Sets this to pass arguments while opening the browser. --> Needs to be a list>>>jsConsoleConfig.headless# Sets wether you want the browser to be headless or not with Selenium --> bool>>>jsConsoleConfig.browsername# Sets the browser you want to use with Selenium ('Chrome', 'Firefox' and 'PhantomJS' are currently supported) --> String"""Default Configuration is:layer = 'Selenium'executable_path = ''no_sandbox = Falseargs = []headless = Truebrowsername = 'Chrome'"""## Experiment and try different browsers and layers to find the one that fits the best for you. I've personnaly tried my module with the default configurations.###### If you don't want to worry about drivers and browsers you can use Pyppeteer which will download, install and set up a browser for you.>>>fromjsConsoleimport*...

jsConsole特定的函数/方法和类。

  • 在浏览器.kill()或窗户。杀了()

用于终止启动时打开的浏览器实例,以防止它在停止脚本/python执行后仍在后台打开。在

Check your activity monitor (top, htop, activity monitor, etc.) if there isn't any non-used browsers opened as it may happen when using Selenium and other browser control softwares.

  • 浏览器(浏览器对象)

包含有关当前打开的浏览器实例的多个信息:

- browser: The browser instance, a new page object if using Pyppeteer or a driver instance if using Selenium
- layer: The name of the layer used (Selenium or Pyppeteer)
- executable_path: The executable path (if specified one) of the browser in use
- browsername: The name of the browser in use (i.e Chrome, Firefox)
- no_sandbox: Wether or not you activated the option no-sandbox (useful for Linux users)
- headless: If you opened the browser instance headlessly (works for Selenium)
- args: The arguments passed (if configured) while opening the browser
- drivername: The name of the driver in use
- connected: Wether or not you are connected to the browser
- areClassesInitialized: Internal variable to indicate if the JavaScript are correctly initialized
- list_of_variables: Internal variable which tells the variables ID created by jsConsole (i.e when using addEventListener or setTimeout)
- dict_of_ids = Internal variable which tells the different setTimeout/setInterval IDs that had been created and if each of them should be enabled or not.
- ids_to_thread = Internal variable which tells the different setTimeout/setInterval IDs that had been created and their corresponding thread.
  • 新鲜()

返回一个具有全新文档和窗口类的元组(在加载新页面后)

这样使用:

>>>document,window,history=fresh()Whichreturnsanewdocument(_Document)objectinthedocumentvariable,anewwindow(_Window)objectinthewindowvariableandanewhistory(_History)objectinthehistoryvariable.## I can't provide a new document and window in real-time, seamlessly (even though I tried) because of the way they work.
  • newDocument():

返回一个新的document(\u document)对象

  • newWindow():

返回一个新窗口(_window)对象

  • newHistory():

返回一个新的history(\u history)对象

  • 求值():

如果需要,评估一段JavaScript代码(即还不可用)

return_value=True adds "return " in front of the snippet of code if you want the value to be returned while using Selenium

  • 在文档.window以及窗口.window将返回一条错误消息,因为我没有找到在不创建递归错误的情况下链接它们的方法。在

您可以在setTimeout()、clearInterval()和addEventListener中使用python函数。

你应该能够像用JavaScript写代码一样编写代码。

© Anime no Sekai - 2020

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

推荐PyPI第三方库


热门话题
java错误:无法解析方法   如何用相同的父标记和子标记在Java中解析XML?   日期使用Java中的时区偏移将本地时间转换为UTC   java如何在多进程、多线程环境中读取文件   WebView中的java弹出式对话框不在当前显示范围内,但在chrome浏览器中运行良好   只有2个参数的java递归二进制搜索方法   无法在java中调用函数   java JavaMail在Tomcat服务器上运行时停止工作   反射通过java程序生成、编译和运行java类   java Android:如何使ListView即使在应用程序关闭后仍保持禁用状态   在JAVA中识别匿名类实例   java渲染一个由三角形组成的立方体,在旋转时会产生奇怪的角度   函数式编程如何基于比较连续的列表元素将Java流减少为布尔值   java如何替换列表中的多个项目?   java Android如何获取随机sqlite数据?   java我已经将useSSL设置为false,但仍然收到警告   java使用动态变量生成jlabel   apachespark:java。lang.NoClassDefFoundError v2TableWithV1回退