【发布时间】:2021-04-28 17:24:42
【问题描述】:
我正在尝试使用 selenium 获取 iframe 的 src,但我找不到如何在 div 中获取 iframe(div 有一个 id)。这是我所拥有的:
<div role="tabpanel" class="tab-pane active" id="video_box" style="background: #000; color: #fff;">
<iframe width="560" height="315" frameborder="0" src="https://embedsito.com/v/x431gb5q0rq76j-" scrolling="no" allowfullscreen=""></iframe>
</div>
如您所见,我可以使用 driver.find_element_by_id("video_box") 通过 id 获取 div,但我需要的是 div 内部的 src,它没有类名、没有 id、没有名称和文本(好吧,它实际上有来自 src 的文本,但它每次都会改变)。有没有办法从 div 中获取 iframe 并从中提取 src?
我尝试使用find_by_css_selector('iframe') 方法但没有结果
我尝试使用find_element_by_tag_name('iframe') 方法,但引发异常:
selenium.common.exceptions.NoSuchElementException:消息:无法定位元素:iframe
【问题讨论】:
标签: python html selenium iframe