在IMDB.com上查找第一个下拉项目的Xpath链接

2024-10-06 09:48:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我似乎找不到适合我所要做的事情的Xpath:

enter image description here

我尝试单击的元素似乎是:

//*[@id="react-autowhatever-1--item-0"]/span/div[2]

但当运行此代码时:

wait = WebDriverWait(imdbScrape.driver, 10)
wait.until(ec.element_to_be_clickable((By.XPATH,
                            '//*[@id="suggestion-search"]'))).send_keys("the"
                            + "fifth element")

searchBar = wait.until(ec.element_to_be_clickable((By.XPATH,
                                 '//*[@id="react-autowhatever-1--item-0"]/span/div[2]')))
searchBar.location_once_scrolled_into_view
urlToScrape = searchBar.get_attribute("href")

print(urlToScrape)

我得到“无”作为结果,我假设这是因为当我在网页上看,我没有看到任何“href”标签,但我想知道如何才能得到第一个选择的链接地址

任何帮助都将不胜感激

谢谢你


Tags: todividbyelementbeitemreact