【发布时间】:2020-11-10 14:55:04
【问题描述】:
所以,这是我遇到问题的代码:
def scrap():
options = webdriver.ChromeOptions();
options.add_argument('headless');
options.add_argument('--profile-directory=Profile 1')
options.add_argument("--user-data-dir=C:/Users/omarl/AppData/Local/Google/Chrome/User Data/")
options.add_argument("--remote-debugging-port=45447")
options.add_argument("--disable-gpu")
browser = webdriver.Chrome(executable_path=r"C:\Users\omarl\OneDrive\Escritorio\chromedriver.exe", options=options)
scrapURL = "https://es.wallapop.com/search?distance=30000&keywords=leggins&latitude=41.38804&longitude=2.17001&filters_source=quick_filters"
browser.get(scrapURL)
#...
还有错误:
WebDriverException: unknown error: unable to discover open pages
当我执行脚本时,我没有任何 chrome 实例,当我在没有 headless 选项的情况下使用它时,它工作正常。知道为什么会这样吗?请注意,我使用的是类似问题中提供的--remote-debuggin-port。
我正在使用 ChromeDriver 86.0.4240.22
【问题讨论】:
-
对于无头版本,您是否也在使用相同的可执行路径?
-
您的路径可能有问题。试试
options.add_argument(r'--user-data-dir="C:\Users\omarl\AppData\Local\Chromium\User Data\Default"')。 -
@Norhther 很难给你一个明确的答案,因为你的问题中省略了可能导致你错误的代码部分。请提供更多详细信息。
标签: python selenium selenium-chromedriver remote-debugging google-chrome-headless