【问题标题】:I have a playlist of songs in youtube and I want to download all of them using Scrapy but I'm able to see the titles of only first 30我在 youtube 上有一个歌曲播放列表,我想使用 Scrapy 下载所有歌曲,但我只能看到前 30 首歌曲的标题
【发布时间】:2023-03-26 02:29:01
【问题描述】:

我在YouTube 中有一个歌曲播放列表,其中包含 100 多首歌曲,我想使用 Scrapy 下载所有歌曲,但我只能看到列表中前 30 首歌曲的标题。请建议我一种从我的播放列表中获取所有歌曲的方法。

到目前为止的代码:

import scrapy
from bs4 import BeautifulSoup

class Playlist_Scraper(scrapy.Spider):
    name = 'find_playlist'

    def start_requests(self):
        urls =[
            'https://www.youtube.com/watch?v=_tNU6dpjIyM&list=RD_tNU6dpjIyM',
        ]
        for url in urls:
            yield scrapy.Request(url=url, callback=self.parse)

    def parse(self, response):
        print(response.css('ahref').attrib['href'])

【问题讨论】:

标签: python python-3.x web-scraping scrapy


【解决方案1】:

'https://www.youtube.com/watch?v=_tNU6dpjIyM&list=RD_tNU6dpjIyM'的内容

从一些 json 元数据开始,例如,如果您搜索“某处”,您会注意到“链接公园 - 我属于某处”的链接数据就在那里。 您只需要提取确切的行。

它是一个脚本标签,结构如下:

<script >
window["ytInitialData"] = {"responseContext": "<data containing all the songs"....}
window["ytInitialPlayerResponse"] = {<more meta data not sure what is is for"}
</script>

【讨论】:

    猜你喜欢
    • 2021-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多