Selenium无法通过XPath查找元素 [英] Selenium can't find elements by XPath

查看:273
本文介绍了Selenium无法通过XPath查找元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于数据是动态的,我正在尝试使用Selenium Chromedriver从页面中提取一些赔率。对于我来说,通过XPath查找元素通常可以在这类网站上使用,但这一次,它似乎无法找到有问题的元素,也找不到属于页面这一部分的所有元素,这些元素均显示了相关赔率。

I'm trying to extract some odds from a page using Selenium Chromedriver, since the data is dynamic. The "find elements by XPath" usually works with these kind of websites for me but this time, it can't seem to find the element in question, nor any element that belong to the section of the page that shows the relevant odds.

我可能正在犯一个简单的错误-如果有人有时间检查页面,我将非常感谢! 北欧投注NHL赔率

I'm probably making a simple error - if anyone has time to check the page out I'd be very grateful! Nordic Bet NHL Odds

driver.get("https://www.nordicbet.com/en/odds#?cat=&reg=&sc=50&bgi=36")
time.sleep(5)
dayElems = driver.find_elements_by_xpath("//div[@class='ng-scope']")
print(len(dayElems))
>>> 0


推荐答案

起初我误会了,对不起,
原来这是我以前经常面对的问题.....

At first I misunderstood, sorry, turn out it is too a problem I used to face.....

它在另一个ID为是SportsbookIFrame,您需要导航到框架

It is in another frame which id is SportsbookIFrame, You need to navigate in to the frame

In [58]: driver.switch_to_frame("SportsbookIFrame")

In [55]: dayElems = driver.find_elements_by_xpath("//div[@class='ng-scope']")

In [56]: len(dayElems)
Out[56]: 26

对于搜索iframe,它们通常是元素:

For searching iframes, they are usual elements:

iframes = driver.find_elements_by_xpath("//iframe")

这篇关于Selenium无法通过XPath查找元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆