【发布时间】:2021-06-19 05:02:28
【问题描述】:
我正在尝试使用无头 WebDriver 和 Selenium 打印 DuckDuckgo 的搜索结果。但是,无论我搜索什么 ID 或类名,无论等待加载多长时间,我都无法找到引用搜索结果的 DOM 元素。
代码如下:
opts = Options()
opts.headless = False
browser = Firefox(options=opts)
browser.get('https://duckduckgo.com')
search = browser.find_element_by_id('search_form_input_homepage')
search.send_keys("testing")
search.submit()
# wait for URL to change with 15 seconds timeout
WebDriverWait(browser, 15).until(EC.url_changes(browser.current_url))
print(browser.current_url)
results = WebDriverWait(browser,10)
.until(EC.presence_of_element_located((By.ID,"links")))
time.sleep(10)
results = browser.find_elements_by_class_name('result results_links_deep highlight_d result--url-above-snippet') # I tried many other ID's and class names
print(results) # prints []
我开始怀疑在 DuckDuckGo 中避免网络抓取存在一些技巧。有人知道吗?
【问题讨论】:
标签: selenium geckodriver