Giter Club home page Giter Club logo

pisebe's Introduction

PI-SeBE: Python Interface for Selenium-Browser-Extension

Description

PI-SeBE is a small python library that lets you create Selenium-Browser-Extension (SeBE) projects and tests from within Python

Links: Selenium ย  Selenium-Browser-Extension

Basic Usage

Basic usage is shown below

import pisebe

# Create a project object. Assign the project a new test
p = pisebe.Project()
p.set_url("https://www.example.com")
test = p.add_test("Test 1")

# Add instructions for the test to do
test.add("open","/")
test.add("pause",4000)
test.add("close")

# Export the project as a .side file (which can then be executed by SeBE)
p.export("open_pause_close_example.side")

Advanced Usage: Webscraping

Another good use case is with webscraping. For example, you can use PI-SeBE to make a SeBE test that webscrapes a set of documentation pages from python.org. Below is an example implementation of this.

import pisebe

# Write a javascript snippet that will download the entire html of a webpage when ran
snippet = '''
const txt = document.documentElement.outerHTML; 
var element = document.createElement('a'); 
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(txt)); 
element.setAttribute('download', 'page.html'); 
element.style.display = 'none'; 
document.body.appendChild(element); 
element.click(); 
document.body.removeChild(element);
'''

# Create a SeBE project to download a set of pages
p = pisebe.Project()
p.set_url("https://docs.python.org/")

main = p.add_test("main")
for library in ["random","fractions","math","pickle","csv","os","time","re"]:
    main.add("open", f"https://docs.python.org/3/library/{library}.html")
    main.add("runScript", snippet)

p.export()

Purpose: Why I made this

I made PI-SeBE while working on a data science project in which I needed to webscrape a website using Selenium. The problem I encountered was that the Selenium-WebDriver needs an internet browser, but I was working from a remote headless server (no internet browser and no graphical interface installed). My solution was to use the Selenium-Browser-Extension (SeBE) from my local desktop and then upload the webscraped data to where it was needed. SeBE already has a built-in IDE, but PI-SeBE connects the two so that you can make your SeBE projects all from within Python.

pisebe's People

Contributors

velzenor avatar

Watchers

 avatar

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.