我正在尝试从一个网站下载视频,他们使用名为ooyala的公司来托管视频,所以我认为您无法通过在页面上搜索元素来找到它。 我正在尝试使用Selenium来单击播放按钮,并通过网络选项卡获取视频的URL。
目前我的代码是这样的:
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
def get_link():
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
caps = DesiredCapabilities.CHROME
caps['loggingPrefs'] = {'browser': 'ALL'}
url_main = r'https://www.channelnewsasia.com/news/video-on-demand/japanhour'
path = r'C:\Users\User\Downloads\Internet download\chromedriver_win32\chromedriver.exe'
driver = webdriver.Chrome(path, chrome_options=chrome_options,desired_capabilities=caps)
driver.get(url_main)
time.sleep(10)
link = driver.find_element_by_class_name('video__custom-duration')
link.click()
while True:
for entry in driver.get_log('browser'):
print(entry)
点击可以使用,但 loggingPrefs 不起作用,我认为它返回了错误信息。我尝试查找文档,但我找不到什么其他类型的 args 可以放入 DesiredCapabilities 字典中。有人能给我一些帮助吗?
TLDR:
如何从 Chrome 的网络选项卡中读取数据?
附加信息。
我使用的网址在新加坡受到地理位置限制,因此这里提供另一个随机视频供任何帮助我的人使用,但没有使用 ooyala。 https://www.rollingstone.com/music/music-news/norwegian-dj-cashmere-cat-goes-spartan-on-with-me-premiere-71196/
如果你用 VPN 访问原始网址,则这是我正在尝试自动查找的链接 https://mediacorp-videosaz.akamaized.net/c642f1d9-bfcd-46fe-8304-b4bf5c236d1e/BsY3hkajE6J_wuuYqP4M6HATpdD8CwlF.ism/QualityLevels(1984000)/Manifest(format=m3u8-aapl)