Git Product home page Git Product logo

pychakra's Introduction

PyChakra

Github Build Status LICENSE VERSION DL

PyChakra is a Python binding to Microsoft Chakra(v1.11.16) Javascript engine.

Chakra is a modern JavaScript engine for Microsoft Edge, it support 96% ES6 feature, Complete info see https://kangax.github.io/compat-table/es6/

Installation

pip install PyChakra

Usage

from PyChakra import Runtime

# create runtime instance
runtime = Runtime()

# eval JavaScript code
runtime.eval("(() => 2)();") # (True, 2)
runtime.eval("(() => a)();") # (False, "ReferenceError: 'a' is not defined")

# set or get variable
runtime.set_variable("foo", "'bar'") # True
runtime.get_variable("foo") # 'bar'

API

eval(js_string)

Eval JavaScript code string.

Parameters:

  • js_string: str: JavaScript code string

Returns: (is_successful: bool, result: any)

  • is_successfully: indicates whether JavaScript is running successfully.
  • result:
    • if s is True, result is the JavaScript running return value.
    • if is_successfully is False and result is string, result is the JavaScript running exception.
    • if is_successfully is False and result is number, result is the chakra internal error code. see(github)

set_variable(variable_name: str, variable_value: any)

Set variable in global scope.

Parameters:

  • variable_name: str: JavaScript variable name.
  • variable_value: str: JavaScript variable value in Python str.

Returns: same as eval

get_variable(variable_name: str)

Get variable in global scope.

Parameters:

  • variable_name: str: JavaScript variable name.

Returns: variable_value: str

  • if returns value is None, it indicates there is no variable_name in the global scope.

Supports

  • Python2 >= 2.7
  • Python3 >= 3.4

Platform

  • macOS x64
  • Linux x64
  • Windows x86/x64 (tested on Windows 10 x64, Python 3.7)

pychakra's People

Contributors

seahoh avatar zhengrenzhe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

satireven

pychakra's Issues

Nice Project. I have a question for you?

I have been developing a Python browser with only raw Python 3. to 3.7. It Request the HTML parses for the CSS url paths and using a second Threaded Request and downloads any and all CSS files, all JavaScript files and all Images into logged type History/Cookie like folders. I have it fully rendering all div blocks traversed, h1-h6, img, p, small and Hyperlinks currently. But without JS is an useless project.

My question is,, do you think PyChakra can read Parsed JavaScript data and fetch the results immediately while parsing several .js files ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.