【发布时间】:2022-11-11 14:10:50
【问题描述】:
当我使用 Selenium 进行一些 Web 自动化工作时,我会在三次运行中遇到此错误。我在谷歌上到处搜索,找不到任何信息,请你帮忙吗?
有问题的代码是:
driver.get("https://www.baidu.com")
kw = WebDriverWait(driver,100).until(EC.presence_of_element_located((By.ID,'kw')))
kw.send_keys('keyword')
su = WebDriverWait(driver,100).until(EC.element_to_be_clickable((By.ID,'su')))
su.click()
content = WebDriverWait(driver,100).until(EC.presence_of_element_located((By.CSS_SELECTOR,"div[id=\"content_left\"]")))
search_res = content.find_elements(By.CLASS_NAME,'result')
for res in search_res:
links = res.find_elements(By.TAG_NAME,"a")
url = links[-1].get_attribute('href')
我试图用find_element() 替换function presence_of_element_located(),但没有运气。
我在用:
- Windows 10,
- python3.10,
- 硒 v4.2
我尝试了各种浏览器的代码,如 chrome96、97、98、105; edge版本106,还是一样的错误,谁能帮忙?谢谢。
【问题讨论】:
-
您能否向我们确认您正在抓取的页面的网址?另外,您可以发布一个最小的可重现示例吗?
-
请发布您尝试过的代码
-
我正在使用代码检查我在百度上的排名,当我去某些页面查找所有 10 个条目时,出现错误。