
利用Python Scrapy构建的网易云音乐(music163)数据抓取系统及完整源码
5星
- 浏览量: 0
- 大小:None
- 文件类型:None
简介:
本项目使用Python Scrapy框架开发了一个针对网易云音乐的数据爬虫系统,涵盖用户歌单、歌曲评论等信息收集功能,并提供完整的代码资源。
基于Python Scrapy实现的网易云音乐数据爬取系统使用了全部源代码,并且是建立在Scrapy框架之上。该系统的爬虫流程如下:
- 以歌手页面为索引,抓取出所有歌手信息;
- 继续从这些歌手页面中获取他们的专辑详情;
- 利用所有的专辑链接进一步提取出每首歌曲的信息;
- 最终捕获并保存歌曲的热门评论。
数据会被存储在Mongodb数据库里。每个文档将包含该歌曲所属的艺术家、歌名、所在专辑,以及热评中的作者信息(包括点赞数和头像URL)。抓取到这些评论者的头像链接是为了后续可能的应用需求,比如展示在一个网页上以便用户查看或互动。
### 运行:
```bash
$ scrapy crawl music
```
以下是示例代码片段:
```python
import time
from pprint import pprint
class WoaiduSpider(BaseSpider):
name = woaidu
start_urls = (http://www.woaidu.org/sitemap_1.html,)
def parse(self,response):
response_selector = HtmlXPathSelector(response)
next_link = list_first_item(response_selector.select(u//div[@class=k2]/div/a[text()=下一页]/@href).extract())
if next_link:
yield Request(url=clean_url(response.url,next_link,response.encoding), callback=self.parse)
for detail_link in response_selector.select(u//div[contains(@class,sousuolist)]/a/@href).extract():
if detail_link:
yield Request(url=clean_url(response.url,detail_link,response.encoding), callback=self.parse_detail)
def parse_detail(self, response):
woaidu_item = WoaiduCrawlerItem()
response_selector = HtmlXPathSelector(response)
# 提取书籍信息
woaidu_item[book_name] = list_first_item(response_selector.select(u//div[@class=zizida][1]/text()).extract())
author_info = [list_first_item(response_selector.select(u//div[@class=xiaoxiao][1]/text()).extract())[5:].strip()]
woaidu_item[author] = author_info
description_text = list_first_item(response_selector.select(u//div[@class=lili][1]/text()).extract()).strip()
woaidu_item[book_description] = description_text
# 提取书籍封面图片URL
```
全部评论 (0)


