Anything II
Anything II

Reputation: 23

Use Python to interact with existing instance of Google Chrome

My aim is to scrape a website on Chrome using Selenium (or a similar module). However, an important aspect of the project is to avoid using a browser controlled by the test software, ie a browser opened using:

driver = webdriver.Chrome('...')
driver.get('https://www.google.com/')

I do understand that Selenium makes this sort of goal very accessible, but certain limitations (such as having to sign into a website, avoiding putting personal details in code, avoiding manual entry of personal details using input) discourage it.

My first step was to use OS to open a new tab in an existing instance of Chrome, one I manually opened, which works great.

os.system(f'start chrome.exe {link}')

This is where I'm stuck. I browsed through the OS directory, but am not sure exactly what to look for. I'm new to this sort of coding so I'm not sure how to proceed, what modules would be helpful here, or where I should look for further help.

TL; DR:

How do I interact (scrape information, navigate page elements, etc...) with a manually opened Chrome browser using Python and Selenium (or other)?

Upvotes: 1

Views: 3009

Answers (1)

PDHide
PDHide

Reputation: 19929

Start chrome with debug port:

<path>\chrome.exe" --remote-debugging-port=1559

And in selenium use :

`System.setProperty("webdriver.chrome.driver", "C:\chromedriver.exe");

ChromeOptions options = new ChromeOptions();

options.setExperimentalOption("debuggerAddress", "127.0.0.1:1559");

WebDriver browser=new ChromeDriver(options);`

Python :

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:1559")
driver = webdriver.Chrome(options=chrome_options)

Upvotes: 1

Related Questions