使用selenium从视频标签获取src

2024-09-28 01:27:23 发布

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

我正在尝试获取此页上的视频链接https://in.news.yahoo.com/video/jitendra-singh-visits-manipur-militants-051500244.html。我尝试了多种方法使用硒,但没有成功。有人能指出我做错了什么吗

driver = webdriver.Chrome()
def getVideoTrend(self, "https://in.news.yahoo.com/video/jitendra-singh-visits-manipur-militants-051500244.html"):
    driver.get(url)
    element = WebDriverWait(driver, 10).until(lambda driver: driver.find_elements_by_class_name('mediavideoplayervppca'))
    video_trend = []
    #s = driver.find_element_by_css_selector('video.yvp-html5-video') #this also does not help
    s = driver.find_elements_by_xpath('//*[@id="yui_3_9_1_1_1434089562443_964"]')
    print s
    print s.get_attribute('src')

请打开chrome中的链接以查看页面元素


Tags: inhttpscomby链接videodriverfind
1条回答
网友
1楼 · 发布于 2024-09-28 01:27:23

在给定的URL中,你只有一个视频标签。所以您可以使用标记名来获取src。在

像这样:

    By byLocator = By.tagName("video");
    new WebDriverWait(driver, 20).until(ExpectedConditions
            .presenceOfElementLocated(byLocator));
    WebElement findElement = driver.findElement(byLocator);
    System.out.println("Src file : " + findElement.getAttribute("src"));

相关问题 更多 >

    热门问题