我试图抓取一个网站,但当我试图运行程序时,我得到了以下错误。以下是我的代码
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.expected_conditions import presence_of_element_located
driver = webdriver.Chrome(executable_path = '/home/danish-khan/webscraping/rgcrawler2/chromedriver')
driver.get('https://www.researchgate.net/institution/Islamia_College_Peshawar/department/Department_of_Computer_Science/members')
chrome_options = Options()
element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, '//*[@id="rgw9_5fac070727fc2"]/div[3]/h5/a]')))
print(element.text)`
Traceback (most recent call last):
File "resgt3.py", line 14, in <module>
element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, '//*[@id="rgw9_5fac070727fc2"]/div[3]/h5/a]')))
File "/home/danish-khan/miniconda3/lib/python3.7/site-packages/selenium/webdriver/support/wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
发布于 2020-11-15 13:23:47
element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, '//*[@id="rgw9_5fac070727fc2"]/div[3]/h5/a]')))
当页面加载时,您的程序等待20
秒以等待XPATH元素'//*[@id="rgw9_5fac070727fc2"]/div[3]/h5/a]'
出现。
如果XPATH元素在定义的时间之后没有出现,就会得到一个超时错误。这是一件好事,否则如果XPATH元素根本不出现,您的程序将永远停滞。
我认为您应该仔细检查所提供的XPATH是否正确,或者它是否没有随着时间的推移而改变。
https://stackoverflow.com/questions/64843218
复制相似问题