抓取网页视频工具(·曼南(KaranMannan)学习用python编写代码 )
优采云 发布时间: 2022-04-11 01:31抓取网页视频工具(·曼南(KaranMannan)学习用python编写代码
)
卡兰·曼南
一两周前,我开始学习用 python 编码。我想创建一些东西,我输入一些歌曲标题的名称,程序将返回一个搜索页面链接和一个指向该歌曲的链接(受不和谐机器人的启发)。我得到了第一部分的工作,搜索页面链接返回就好了,但我不知道如何链接这首歌。所以我想如果我能打印弹出的第一个视频标题会很好,因为在大多数情况下,第一个链接是必需的。所以我做了一个爬虫来爬取视频的所有链接,我会返回第一个。这部分不起作用...但是,相同的爬虫代码可以用于其他网站。我不知道这个...
from bs4 import BeautifulSoup
import requests
import urllib
def milo():
User_input = input("Title of Youtube vid - ")
words = User_input.split()
list = []
list.append('+'.join(words))
print("https://www.youtube.com/results?search_query=" + list[0])
url = "https://www.youtube.com/results?search_query=" + list[0]
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text, 'html.parser')
for link in soup.findAll('a',"video-title"):
song = link.get('href')
list.append('https://www.youtube.com' + song)
print(list[0])
milo()