lundi 6 août 2018

Chrome driver not working headlessly with Python and Selenium?

I am new to Selenium programming with Python. The code works fine without the --headless argument, but does not execute at all when I try to run it headlessly. Could someone help me out with it?

Below is my sample code, I am using Python 3.

from selenium import webdriver from selenium.webdriver.common.keys import Keys from bs4 import BeautifulSoup import time import requests from selenium.webdriver.chrome.options import Options

options = Options() options.set_headless(headless=True) driver = webdriver.Chrome(chrome_options=options, executable_path=r'E:/Python/[FreeTutorials.Us] Udemy - python-master-web-scraping-course-doing-20-real-projects/03 Step _ Download HTML Content/chromedriver.exe') driver.get("https://www.tirerack.com/survey/ValidationServlet?autoYear=2006&autoMake=Porsche&autoModel=911%20Carrera%20S%20Cabriolet&newDesktop=true") print ("Headless Chrome Initialized")

html_doc=driver.page_source soup= BeautifulSoup(html_doc,'lxml')

print(soup) driver.quit()

Aucun commentaire:

Enregistrer un commentaire