我正在尝试在此页面上获取视频链接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中打开链接以查看页面元素
答案 0 :(得分:0)
在该给定的网址中,您只有一个视频标记。所以你可以使用tagName获得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"));