Py学习  »  Python

使用selenium python抓取视频

Thomas • 9 月前 • 296 次点击  

我正在尝试从中抓取视频 任何url 由用户输入。问题是,由于我不知道视频的名称,也不知道具体的网站,我不知道自己在寻找什么。我试着这样使用BeautifulSoup:

import requests
from bs4 import BeautifulSoup
 
r = requests.get(Web_url)
 
soup = BeautifulSoup(r.content, 'html.parser')

video_tags = soup.findAll('video')
 
for video_tag in video_tags:
    video_url = video_tag.find("a")['href']
    print(video_url) 

但据我所知,只有当视频在html中时,这可能才有效。我试过很多这样的网站,但似乎什么都没有出现。我也尝试过:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(options=chrome_options)
driver.get(url)
videos = driver.find_element(By.TAG_NAME, 'video')
for video in videos:
    print(video.get_attribute('src'))

但这给了我一个错误:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"video"}   (Session info: headless chrome=107.0.5304.107)

我不知道还能尝试什么。谷歌上有很多资源专门用于抓取Youtube视频,其中一半告诉我使用Youtube下载模块。如果你能帮我解决这个问题,我将不胜感激。谢谢

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/158617
 
296 次点击  
文章 [ 1 ]  |  最新文章 9 月前