Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide Chrome Driver in python?

Though I knew people asked this question but I didn't find suitable answer so I asked again. I used PhantomJS to scrape web site, but it is very slow on Mac, so I want to tru Chrome but Chrome show browser that is is bad, can I hide it? I tried code as below, that still show a small browser window..

browser = webdriver.Chrome()
browser.set_window_position(0, 0)
browser.set_window_size(0, 0)
like image 275
mikezang Avatar asked Feb 27 '17 02:02

mikezang


People also ask

Can websites detect ChromeDriver?

The answer is YES! Websites can detect the automation using JavaScript experimental technology navigator. webdriver in the navigator interface.

How do I close a Chrome window in Python?

close() method is used to close the current browser window on which the focus is set, on the other hand quit() method essentially calls the driver.

What is ChromeDriver Python?

ChromeDriver is a separate executable that Selenium WebDriver uses to control Chrome. It is maintained by the Chromium team with help from WebDriver contributors. If you are unfamiliar with Selenium WebDriver, you should check out the Selenium site.


3 Answers

Google announced in 4/2017 you can run in headless.

https://developers.google.com/web/updates/2017/04/headless-chrome

chrome_options = Options()
# Chrome v75 and lower:
# chrome_options.add_argument("--headless") 
# Chrome v 76 and above (v76 released July 30th 2019):
chrome_options.headless = True

chrome_options.binary_location = '/Applications/Google Chrome   Canary.app/Contents/MacOS/Google Chrome Canary'  
driver = webdriver.Chrome(executable_path=os.path.abspath(“chromedriver"),   chrome_options=chrome_options)

Few things you should make sure

  • If using Mac/Linux then chrome version should be minimum 59
  • If using Windows then chrome version should be minimum 60
  • Use the latest chromedriver as well to make sure you don't have compatibility issue
like image 52
sealabr Avatar answered Sep 22 '22 07:09

sealabr


REF: how-could-i-start-a-selenium-browserlike-firefox-minimized

You can move browser window over the monitor, like this:

driver.set_window_position(-10000,0)

like image 32
Beomi Avatar answered Sep 23 '22 07:09

Beomi


Try This!

https://beomi.github.io/2017/09/28/HowToMakeWebCrawler-Headless-Chrome/

options = webdriver.ChromeOptions()
options.add_argument('headless')
options.add_argument('window-size=1920x1080')
options.add_argument("disable-gpu")
# OR options.add_argument("--disable-gpu")

driver = webdriver.Chrome('chromedriver', chrome_options=options)
like image 34
Henry Lee Avatar answered Sep 24 '22 07:09

Henry Lee