Alternatives to execute a selenium script

788 Views Asked by At

I have a selenium script with python 3. I need to run it every day at 7AM for 5 minutes but I cannot leave my laptop on 24/7 just for it. What would be the easiest/best alternative?

I checked Lambda AWS but I am unable to install chrome (or the headless version of it) there and I have no experience with servers.

2

There are 2 best solutions below

2
Todor Minakov On BEST ANSWER

AWS Lambda is a viable solution for your goal - especially if the script is going to have a small runtime. They have recently increased the maximum execution time to 15 minutes, so you should be ok.

Getting headless Chrome in Lambda (in Python; it's full of JS/node.js solutions out there :)) is doable - I myself have used successfully this project in the past - https://github.com/21Buttons/pychromeless

To schedule the execution at your desired time you could use Amazon's CloudWatch.

1
undetected Selenium On

To execute a Selenium script with Python 3 without installing a browser you can use the GhostDriver.

GhostDriver

Ghost Driver is an implementation of the Remote WebDriver protocol using PhantomJS as back-end. GhostDriver is designed to be integral part of PhantomJS itself with JavaScript API.

Additional WebDriver Capabilities through GhostDriver

  • phantomjs.page.settings.SETTING = VALUE
  • phantomjs.page.customHeaders.HEADER = VALUE
  • phantomjs.page.whitelist
  • phantomjs.page.blacklist
  • unhandledPromptBehavior
  • loggingPrefs
  • phantomjs.binary.path
  • phantomjs.ghostdriver.path
  • phantomjs.cli.args
  • phantomjs.ghostdriver.cli.args

Main Advantages of GhostDriver

  • Screen Capture
  • Page Automation
  • Network Monitoring
  • To run Unit tests on command line
  • Combined with QUnit for the test suite

An Example

  • Code Block :

    from selenium import webdriver
    
    driver = webdriver.PhantomJS(executable_path='/path/to/phantomjs')
    driver.get('https://www.google.com/')
    print(driver.title)
    driver.quit()
    
  • Console Output:

    Google