Coder Social home page Coder Social logo

aflorithmic / pythonista-chromeless Goto Github PK

View Code? Open in Web Editor NEW

This project forked from umihico/pythonista-chromeless

0.0 0.0 0.0 105.19 MB

Serverless selenium which dynamically execute any given code.

Home Page: https://pypi.org/project/chromeless/

Python 76.50% Dockerfile 8.37% Shell 15.12%

pythonista-chromeless's Introduction

chromeless

AWS lambda unit which execute given code on selenium

Example

# write the code as method of selenium.webdriver.Chrome
def get_title(self, url):
    self.get(url)
    return self.title

# prepare your credentials
gateway_url = "https://XXXXXXXXXX.execute-api.us-west-2.amazonaws.com/default/chromeless"
gateway_apikey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

# Then attach the function and just call it.
from chromeless import Chromeless
chrome = Chromeless(gateway_url, gateway_apikey)
chrome.attach_method(get_title)
chrome.get_title("https://google.com") # Google

Installing

  1. AWS environment
    • Create new lambda function
    • Select [Code entry type] and [Upload a .ZIP file]
    • Upload deploy_package.zip
    • Increase the timeout setting and the memory setting enough
    • Create API Gateway for this lambda and note the url and apikey
  2. Local environment
    • pip install chromeless
    • download examples.py
    • put your credentials as awsgateway_apikey and awsgateway_url in examples.py

That's it! Now run the examples.py and change it as you want!

Tips

  • One call, One instance. Solution is wrapping.
# BAD EXAMPLE
chrome = Chromeless(awsgateway_url, awsgateway_apikey)
chrome.get("https://google.com") # lambda get triigered here
chrome.save_screenshot("screenshot.png") # so next method won't work

# SOLUTION
def wrapper(self,url,filename):
    self.get(url)
    self.save_screenshot(filename)

chrome = Chromeless(awsgateway_url, awsgateway_apikey)
chrome.attach_method(wrapper)
chrome.wrapper("https://google.com","screenshot.png")
  • you can set chrome_options to change window resolution
chrome_options = ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--window-size=1920x1080")
# chrome_options.add_argument("--window-size=1280x1696") # DEFAULT
chrome_options.add_argument("--disable-application-cache")
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--hide-scrollbars")
chrome_options.add_argument("--enable-logging")
chrome_options.add_argument("--log-level=0")
chrome_options.add_argument("--single-process")
chrome_options.add_argument("--ignore-certificate-errors")
chrome_options.add_argument("--homedir=/tmp")
chrome = Chromeless(awsgateway_url, awsgateway_apikey, chrome_options=chrome_options)

pythonista-chromeless's People

Contributors

umihico 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.