Giter Club home page Giter Club logo

webfriend's Introduction

   “Your friendly friend in modern web automation and testing.”

Overview

Webfriend is a Python library and command-line utility that integrates with the Chrome DevTools Protocol to control a Google Chrome or Chromium browser instance. There is also a purpose-built scripting language (called Friendscript) that is designed to be an easy-to-learn alternative to Python for writing simple or complex browser automation scripts.

Some of the things that you can use Webfriend for:

  • Take full-page screenshots of web pages.

  • Automate tedious or repetitive tasks on web pages that otherwise would require extensive user input with a keyboard, mouse, or touchscreen device.

  • Execute pre-defined tests against web pages and serve as an automated testing framework for verifying frontend functionality.

  • Automatically login to websites with complex authentication flows.

  • Extract (i.e. scrape) information from web pages and present it in a structured way that other languages and scripts can use as input.

  • Inject Javascript code into the browser, evaluate it, then return the results for output or further processing.

Operation and Usage

Webfriend by default operates using Headless Chrome mode, but can also just as easily run Chrome in the foreground in a graphical environment. Importantly, headless operation allows you to run Webfriend on servers without running Xfvb or X11. In this sense, it operates as a potentially-faster alternative to phantomjs or Selenium while also providing almost all of the capabilities of the complete Google Chrome/Chromium browser.

Using Friendscript, straightforward and composable scripts can be written and combined together to create fast, modular, and flexible processes that can be used to solve real problems.

Installation

git clone https://github.com/ghetzel/webfriend.git
cd webfriend

# Three Options:

# 1. user-level package install
python setup.py install --user

# 2. system-level package install
python setup.py install

# 3. local environment, invoke with `./env/bin/webfriend`
make

Documentation

webfriend's People

Contributors

ghetzel avatar

Stargazers

 avatar Eduardorandom avatar מקס חיים avatar  avatar Sri Kadimisetty avatar Kyle 'Essobi' Stone avatar Michael Mooney avatar  avatar Sarkis Derderian avatar  avatar RAVI MISHRA avatar  avatar  avatar  avatar Syrus Akbary avatar Juan Riaza avatar pepe avatar Tom Atkins avatar Steve Morin avatar sadnoodles avatar JamCh01 avatar Jason Katzer (corp account) avatar Robert Ely avatar Jimmy Li avatar spike grobstein avatar Ben Nied avatar Chris Richards avatar cam avatar Nathan Milford avatar

Watchers

James Cloos avatar  avatar  avatar  avatar  avatar

Forkers

performline

webfriend's Issues

Add run command to invoke other scripts

This task is to create a run command that will take a required parameter specifying the filename of the script to run. A series of paths prefixes will be searched to locate a matching file. The order should be:

  • ./filename
  • Values in colon-separated WEBFRIEND_PATH environment variable (if specified)
  • Default platform-specific paths as defined in the library.

The command options should specify parameters for how the script should be evaluated:

  • scope (false, object):. If false, the script will run without access to the calling scope. If an object is specified, only these values will be added to the scope the script executes in. Both values will create an isolated scope and cause the running script to be unable to write directly to the calling scope.

Indexing a List of elements

Hiya,

I got a list of elements with the following line:
xpath "button[class='_qv64e _gexxb _4tgw8 _njrw0']" -> $buttons. What I would like to do is click the first element of $buttons with the click command - something like: click $buttons[0]. However, friendscript doesn't currently support indexing so currently I'm using a loop that breaks after the first iteration.

Webfriend is my friendly friend and he/she/they/xem deserve indexing.

I think I can fix your problem

https://github.com/ghetzel/webfriend/blob/master/webfriend/rpc/dom.py#L627

I meet the same problem as yours. And I got your code~
When I wanna give it up, I find if I use DOM.getDocument before DOM.performSearch, the DOM.getSearchResults works well!

here is my code, but I dont used your lib~

from chromeremote import ChromeTab, TabTimeout
from time import sleep, time


def common(kwargs):
    current_tab = kwargs.get('current_tab')
    nodeIds = kwargs.get('nodeIds')
    for nodeId in nodeIds:
        print nodeId


def callret(kwargs):
    searchId = kwargs.get('searchId')
    current_tab = kwargs.get('current_tab')
    resultCount = kwargs.get('resultCount')
    current_tab.DOM.getSearchResults(
        searchId=searchId, fromIndex=0, toIndex=resultCount, callback=common)


def main():
    tab = ChromeTab('127.0.0.1', 9222)
    tab.open_tab()
    tab.Network.enable(
        maxTotalBufferSize=10000000, maxResourceBufferSize=5000000)
    tab.Page.enable()
    tab.DOM.enable()
    tab.Overlay.enable()
    tab.CSS.enable()
    tab.Page.navigate(url='https://segmentfault.com/')
    sleep(3)
    tab.DOM.getDocument()
    tab.DOM.performSearch(
        nodeId=0,
        query='python',
        includeUserAgentShadowDOM=False,
        callback=callret)
    try:
        for msg in tab.messages(timeout_return_none=True):
            if time() - tab.start_time > 5:
                break
            if msg is None:
                continue
            with open('log.txt', 'a') as f:
                f.write(str(msg) + '\n')
    except TabTimeout:
        pass


if __name__ == '__main__':
    main()

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.