【发布时间】:2018-08-06 10:35:15
【问题描述】:
我是使用 Python 进行 Selenium 编程的新手。该代码在没有 --headless 参数的情况下可以正常工作,但是当我尝试无头运行它时根本不会执行。有人可以帮我解决吗?
以下是我的示例代码,我使用的是 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()
【问题讨论】:
-
路径中似乎有错误。更改 Python 主路径 (C:\Python34) 中的驱动程序并更改脚本中的路径。
-
没有正确的路径,我已经检查过
标签: python-3.x web web-scraping