【问题标题】:How do I get the href content of a video with seleniun inside an iframe?如何在 iframe 中获取带有 selenium 的视频的 href 内容?
【发布时间】:2021-10-16 08:30:53
【问题描述】:

我想获取包含视频的 href 内容时遇到问题。我必须进入页面并点击视频,一旦我点击视频,页面上就会出现href,直到我点击我得到的视频,然后我无法进入href。

这是页面的代码

HTML

代码更长,href 在 iframe 内,但老实说,我不知道如何从 html 复制文本,所以我发送了图像.. 我想获取 iagen 显示的 href 内容,但它没有到达那里。当我点击视频时,该内容就会出现。接下来我留下我的代码

from selenium import webdriver
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.common.by import By
from selenium.webdriver.chrome.options import Options
import time, re, requests

algo = "Player YouTube"
driver.get("https://www.supertelevisionhd.net/dragon-ball-z-en-vivo/")
time.sleep(1)
driver.switch_to.frame(driver.find_element_by_xpath("//*[@id='post-100']/div/center/iframe"))
time.sleep(1)
click1 = driver.find_element_by_xpath('//*[@id="{}"]'.format(algo))
time.sleep(5)
click1.click()
WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, '/html/body/iframe')))
time.sleep(5)
enlace = WebDriverWait(driver, 10).until(EC.element_to_be_selected((By.CLASS_NAME,'html5-vpl_title_l vpl-antialiased')))
print(enlace)

这是我得到的错误

> File "C:\Users\Nico\Desktop\pruebas driver.py", line 36, in <module>
> enlace = WebDriverWait(driver,
> 10).until(EC.element_to_be_selected((By.CLASS_NAME,'html5-vpl_title_l
> vpl-antialiased'))) File
> "C:\Python39\lib\site-packages\selenium\webdriver\support\wait.py",
> line 71, in until value = method(self._driver) File
> "C:\Python39\lib\site-packages\selenium\webdriver\support\expected_conditions.py",
> line 329, in call return self.element.is_selected() AttributeError:
> 'tuple' object has no attribute 'is_selected'

如果有任何帮助,我将不胜感激。我再说一遍,我要获取的是href的内容,也就是http://ok.ru所说的……

谢谢

【问题讨论】:

  • 您的代码中的is_selected 在哪里?我没看到。
  • 对不起,我不太懂英文,听不懂你的问题

标签: python selenium video iframe href


【解决方案1】:

错误是因为您在最后一行传递了tuple 而不是element

将代码中的最后一行更改为:

enlace = WebDriverWait(driver, 10).until(EC.element_to_be_selected(By.CLASS_NAME,'html5-vpl_title_l vpl-antialiased'))

您添加了一个额外的括号 (),因此出现了错误。

【讨论】:

  • 现在我收到此错误:Traceback(最近一次调用最后一次):文件“C:\Users\xxx\Desktop\PRUEBA\SELENIUM\PRUEBAS\pruebas driver.py”,第 45 行,在 enlace = WebDriverWait(driver, 10).until(EC.element_to_be_selected(By.CLASS_NAME,'html5-vpl_title_l vpl-antialiased')) TypeError: __init__() 接受 2 个位置参数,但给出了 3 个
猜你喜欢
  • 2018-10-30
  • 2012-08-09
  • 1970-01-01
  • 2015-10-28
  • 1970-01-01
  • 2015-07-23
  • 2021-11-20
  • 2021-07-18
  • 2015-07-26
相关资源
最近更新 更多