1

I have a JavaScript code that I need to run on chrome console. I can upload it and run it on Chrome, but I'm trying to automate that by writing a Python script that does the same. Here is what the python script should do:

1) Take in input from the user, using Command Line arguments in python. e.g.:

python FileName.py --from www.abc.com --to www.def.com

2) Update 2 variables in said DoSomething.JS as:

var from_site = "www.abc.com"
  var to_site = "www.def.com"

3) Upload the JS file to chrome and run it in console.

4) The JS file does its job and downloads something. Parse the data through python (I can do this) and run some other commands in said chrome console, all through the same script.

Is there a library I can look up in order to do this? I'm trying to run the python script locally on my laptop.

D Pal
  • 13
  • 7
  • Would this help: https://stackoverflow.com/questions/44010059/execute-js-code-on-page-from-python – Arnav Borborah Sep 09 '19 at 20:02
  • You may want to look into running that Javascript with Node instead of with Chrome. Node has a Javascript runtime and can execute your JS source. If, for some reason, this code has to run in a browser, then look into Puppeteer (or its Python port: pyppeteer), which is a headless browser that you can control from another application. – Arash Motamedi Sep 09 '19 at 20:02
  • @ArashMotamedi The reason I need it to run with Chrome is because the JS file runs in an environment in chrome. I cannot run it locally with node because some of the commands inside the JS file are defined in the environment itself. Locally, those commands are not accessible. – D Pal Sep 09 '19 at 20:09
  • You could consider making a chrome extension or tampermonkey script that communicates with your python application via pinging localhost. – noɥʇʎԀʎzɐɹƆ Sep 09 '19 at 20:30

0 Answers0