【发布时间】:2021-09-09 21:15:10
【问题描述】:
我一直在尝试使用 Python 中的 Selenium 获取 YouTube 视频的上传日期(如下图所示)。
我的代码如下:
! pip install selenium
from selenium import webdriver
! pip install beautifulsoup4
from bs4 import BeautifulSoup
driver = webdriver.Chrome('D:\chromedrive\chromedriver.exe')
driver.get("https://www.youtube.com/watch?v=CoR72I5BGUU")
soup = BeautifulSoup(driver.page_source, 'lxml')
upload_date=driver.find_elements_by_xpath('//*[@id="info-strings"]/yt-formatted-string')
print(upload_date)
但是,无论我使用upload_date=soup.findAll('span', class_='style-scope ytd-grid-video-renderer') 还是upload_date=driver.find_elements_by_xpath('//*[@id="info-strings"]/yt-formatted-string'),它都不起作用。
如果有人知道问题出在哪里,请帮助我。
【问题讨论】:
标签: python selenium beautifulsoup youtube