Compare commits
24 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
98959fef02 | 2 years ago |
|
|
b4cbffe00a | 2 years ago |
|
|
c3be8b9253 | 2 years ago |
|
|
c93abbdb66 | 2 years ago |
|
|
7bdd58e6e9 | 2 years ago |
|
|
24c4fea24e | 2 years ago |
|
|
cce81fa81a | 2 years ago |
|
|
6eceb6f87e | 2 years ago |
|
|
86a9e4315d | 2 years ago |
|
|
8b4c2c0c01 | 2 years ago |
|
|
6f977711c4 | 2 years ago |
|
|
00b1a3e390 | 2 years ago |
|
|
6d36dc28ae | 2 years ago |
|
|
70e14d5164 | 2 years ago |
|
|
ae912d2914 | 2 years ago |
|
|
817b9e3fd6 | 2 years ago |
|
|
b7b80535d3 | 2 years ago |
|
|
1050cfaaa0 | 2 years ago |
|
|
540637cd30 | 2 years ago |
|
|
a16b785abd | 2 years ago |
|
|
5a1df41ed1 | 2 years ago |
|
|
2ee52683fa | 2 years ago |
|
|
bc97683b0b | 2 years ago |
|
|
9297c735a3 | 2 years ago |
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 223 KiB |
|
After Width: | Height: | Size: 51 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,12 @@
|
||||
# Define here the models for your scraped items
|
||||
#
|
||||
# See documentation in:
|
||||
# https://docs.scrapy.org/en/latest/topics/items.html
|
||||
|
||||
import scrapy
|
||||
|
||||
|
||||
class MusiclistdemoItem(scrapy.Item):
|
||||
# define the fields for your item here like:
|
||||
# name = scrapy.Field()
|
||||
pass
|
||||
@ -0,0 +1,28 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Define your item pipelines here
|
||||
#
|
||||
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
|
||||
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
|
||||
|
||||
|
||||
class musicListdemoPipeline(object):
|
||||
def process_item(self, item, spider):
|
||||
return item
|
||||
|
||||
|
||||
class musicListdemoInfoPipeline(object):
|
||||
def open_spider(self, spider):
|
||||
self.f = open('musicListdemoInfo.txt', 'w')
|
||||
|
||||
def close_spider(self, spider):
|
||||
self.f.close()
|
||||
|
||||
def process_item(self, item, spider):
|
||||
try:
|
||||
line = str(dict(item)) + '\n'
|
||||
self.f.write(line)
|
||||
except:
|
||||
pass
|
||||
return item
|
||||
|
||||
@ -0,0 +1,90 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Scrapy settings for BaiduStocks project
|
||||
#
|
||||
# For simplicity, this file contains only settings considered important or
|
||||
# commonly used. You can find more settings consulting the documentation:
|
||||
#
|
||||
# http://doc.scrapy.org/en/latest/topics/settings.html
|
||||
# http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html
|
||||
# http://scrapy.readthedocs.org/en/latest/topics/spider-middleware.html
|
||||
|
||||
BOT_NAME = 'musicListdemo'
|
||||
|
||||
SPIDER_MODULES = ['musicListdemo.spiders']
|
||||
NEWSPIDER_MODULE = 'musicListdemo.spiders'
|
||||
|
||||
|
||||
# Crawl responsibly by identifying yourself (and your website) on the user-agent
|
||||
#USER_AGENT = 'BaiduStocks (+http://www.yourdomain.com)'
|
||||
|
||||
# Obey robots.txt rules
|
||||
ROBOTSTXT_OBEY = True
|
||||
|
||||
# Configure maximum concurrent requests performed by Scrapy (default: 16)
|
||||
#CONCURRENT_REQUESTS = 32
|
||||
|
||||
# Configure a delay for requests for the same website (default: 0)
|
||||
# See http://scrapy.readthedocs.org/en/latest/topics/settings.html#download-delay
|
||||
# See also autothrottle settings and docs
|
||||
#DOWNLOAD_DELAY = 3
|
||||
# The download delay setting will honor only one of:
|
||||
#CONCURRENT_REQUESTS_PER_DOMAIN = 16
|
||||
#CONCURRENT_REQUESTS_PER_IP = 16
|
||||
|
||||
# Disable cookies (enabled by default)
|
||||
#COOKIES_ENABLED = False
|
||||
|
||||
# Disable Telnet Console (enabled by default)
|
||||
#TELNETCONSOLE_ENABLED = False
|
||||
|
||||
# Override the default request headers:
|
||||
#DEFAULT_REQUEST_HEADERS = {
|
||||
# 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
||||
# 'Accept-Language': 'en',
|
||||
#}
|
||||
|
||||
# Enable or disable spider middlewares
|
||||
# See http://scrapy.readthedocs.org/en/latest/topics/spider-middleware.html
|
||||
#SPIDER_MIDDLEWARES = {
|
||||
# 'BaiduStocks.middlewares.BaidustocksSpiderMiddleware': 543,
|
||||
#}
|
||||
|
||||
# Enable or disable downloader middlewares
|
||||
# See http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html
|
||||
#DOWNLOADER_MIDDLEWARES = {
|
||||
# 'BaiduStocks.middlewares.MyCustomDownloaderMiddleware': 543,
|
||||
#}
|
||||
|
||||
# Enable or disable extensions
|
||||
# See http://scrapy.readthedocs.org/en/latest/topics/extensions.html
|
||||
#EXTENSIONS = {
|
||||
# 'scrapy.extensions.telnet.TelnetConsole': None,
|
||||
#}
|
||||
|
||||
# Configure item pipelines
|
||||
# See http://scrapy.readthedocs.org/en/latest/topics/item-pipeline.html
|
||||
ITEM_PIPELINES = {
|
||||
'musicListdemo.pipelines.musicListdemoInfoPipeline': 300,
|
||||
}
|
||||
|
||||
# Enable and configure the AutoThrottle extension (disabled by default)
|
||||
# See http://doc.scrapy.org/en/latest/topics/autothrottle.html
|
||||
#AUTOTHROTTLE_ENABLED = True
|
||||
# The initial download delay
|
||||
#AUTOTHROTTLE_START_DELAY = 5
|
||||
# The maximum download delay to be set in case of high latencies
|
||||
#AUTOTHROTTLE_MAX_DELAY = 60
|
||||
# The average number of requests Scrapy should be sending in parallel to
|
||||
# each remote server
|
||||
#AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0
|
||||
# Enable showing throttling stats for every response received:
|
||||
#AUTOTHROTTLE_DEBUG = False
|
||||
|
||||
# Enable and configure HTTP caching (disabled by default)
|
||||
# See http://scrapy.readthedocs.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
|
||||
#HTTPCACHE_ENABLED = True
|
||||
#HTTPCACHE_EXPIRATION_SECS = 0
|
||||
#HTTPCACHE_DIR = 'httpcache'
|
||||
#HTTPCACHE_IGNORE_HTTP_CODES = []
|
||||
#HTTPCACHE_STORAGE = 'scrapy.extensions.httpcache.FilesystemCacheStorage'
|
||||
@ -0,0 +1,4 @@
|
||||
# This package will contain the spiders of your Scrapy project
|
||||
#
|
||||
# Please refer to the documentation for information on how to create and manage
|
||||
# your spiders.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,75 @@
|
||||
import scrapy
|
||||
import pandas as pd
|
||||
# music_detail.py
|
||||
|
||||
|
||||
INDEX = "C:\\Users\\aaa\\Desktop\\spiders163\\data\\url.csv"
|
||||
DETAIL = "C:\\Users\\aaa\\Desktop\\spiders163\\data\\detail.csv"
|
||||
#scrapy crawl music_index
|
||||
|
||||
class MusicIndexSpider(scrapy.Spider):
|
||||
name = "music_detail"
|
||||
|
||||
redis_key = 'music_detail'
|
||||
|
||||
def start_requests(self):
|
||||
df = pd.read_csv(INDEX, header=None, names=['url', 'title', 'play','user'])
|
||||
|
||||
headers_chrome = {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
|
||||
'Chrome/120.0.0.0 Safari/537.36'
|
||||
}
|
||||
|
||||
for i in df['url']:
|
||||
url = 'https://music.163.com' + i
|
||||
yield scrapy.Request(url, headers=headers_chrome)
|
||||
|
||||
def parse(self, response):
|
||||
|
||||
# 获取歌单标题
|
||||
title = response.css('h2::text')[0].get().replace(',', ' ')
|
||||
|
||||
# 获取标签
|
||||
tags = []
|
||||
tags_message = response.css('.u-tag i::text')
|
||||
|
||||
for p in tags_message:
|
||||
tags.append(p.get())
|
||||
|
||||
# 对标签进行格式化
|
||||
if len(tags) > 1:
|
||||
tag = '-'.join(tags)
|
||||
elif len(tags):
|
||||
tag = tags[0]
|
||||
else:
|
||||
tag = '无'
|
||||
|
||||
# 获取歌单介绍
|
||||
if response.css('#album-desc-more::text'):
|
||||
text = response.css('#album-desc-more::text')[0].get().replace('\n', '').replace(',', ' ')
|
||||
else:
|
||||
text = '无'
|
||||
|
||||
# 获取歌单收藏量
|
||||
collection = response.css('#content-operation i::text')[1].get().replace('(', '').replace(')', '')
|
||||
|
||||
# 歌单播放量
|
||||
play = response.css('.s-fc6::text')[0].get()
|
||||
|
||||
# 歌单内歌曲数
|
||||
songs = response.css('#playlist-track-count::text')[0].get()
|
||||
|
||||
# 歌单评论数
|
||||
comments = response.css('#cnt_comment_count::text')[0].get()
|
||||
|
||||
# 输出歌单详情页信息
|
||||
print('\r', title, tag, text, collection, play, songs, comments, end='', flush=True)
|
||||
|
||||
# # 输出歌单详情页信息
|
||||
print('\r', title, text, collection, play, songs, comments, end='', flush=True)
|
||||
|
||||
# 将详情页信息写入CSV文件中
|
||||
with open(DETAIL, 'a+', encoding='utf-8-sig') as f:
|
||||
f.write(title + ',' + tag + ',' + text + ',' + collection + ',' + play + ',' + songs + ',' + comments +'\n')
|
||||
|
||||
print("\n已获取歌单的信息,保存至 data/detail.csv")
|
||||
@ -0,0 +1,38 @@
|
||||
import scrapy
|
||||
import time
|
||||
import pandas as pd
|
||||
# music_name.py
|
||||
|
||||
INDEX = "C:\\Users\\aaa\\Desktop\\spiders163\\data\\url.csv"
|
||||
NAME = "C:\\Users\\aaa\\Desktop\\spiders163\\data\\name.csv"
|
||||
|
||||
|
||||
class MusicIndexSpider(scrapy.Spider):
|
||||
name = "music_name"
|
||||
|
||||
def start_requests(self):
|
||||
urls = []
|
||||
|
||||
df = pd.read_csv(INDEX, header=None, names=['url', 'title', 'play','user'])
|
||||
headers_iphone = {
|
||||
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25'
|
||||
}
|
||||
|
||||
for i in df['url']:
|
||||
url = 'https://music.163.com' + i
|
||||
|
||||
yield scrapy.Request(url, headers=headers_iphone)
|
||||
|
||||
def parse(self, response):
|
||||
|
||||
li = response.css('.sgchfl .f-thide.sgtl::text')
|
||||
|
||||
for j in li:
|
||||
print(j.get())
|
||||
text = j.get()
|
||||
with open(NAME, 'a+', encoding='utf-8-sig') as f:
|
||||
f.write(j.get().replace(",", " ") + '\n')
|
||||
|
||||
|
||||
print("\n已获取歌单详情页的信息,保存至 data/name.csv")
|
||||
|
||||
@ -0,0 +1,40 @@
|
||||
import scrapy
|
||||
# music_url.py
|
||||
|
||||
INDEX = "C:\\Users\\aaa\\Desktop\\spiders163\\data\\url.csv"
|
||||
|
||||
|
||||
class MusicIndexSpider(scrapy.Spider):
|
||||
name = "music_index"
|
||||
|
||||
def start_requests(self):
|
||||
urls = []
|
||||
for i in range(35, 1505, 35):
|
||||
url = f'https://music.163.com/discover/playlist/?cat=80后&order=hot&limit=35&offset={i}'
|
||||
urls.append(url)
|
||||
|
||||
for url in urls:
|
||||
user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|
||||
yield scrapy.Request(url, headers={'User-Agent': user_agent})
|
||||
|
||||
def parse(self, response):
|
||||
|
||||
# 获取包含歌单详情页网址的标签
|
||||
ids = response.css('.dec a')
|
||||
|
||||
# 获取包含歌单索引页信息的标签
|
||||
# lis = response.css('#m-pl-container li')
|
||||
# print('\r', len(lis), end='', flush=True)
|
||||
|
||||
for id in ids:
|
||||
# 获取歌单详情页地址
|
||||
url = id.attrib['href']
|
||||
|
||||
# 输出歌单索引页信息
|
||||
print('\r', url, end='', flush=True)
|
||||
|
||||
# 将索引页写入CSV文件中
|
||||
with open(INDEX, 'a+', encoding='utf-8') as f:
|
||||
f.write(url + '\n')
|
||||
|
||||
print("\n已获取歌单索引页的信息,保存至 data/list.csv")
|
||||
@ -0,0 +1,11 @@
|
||||
# Automatically created by: scrapy startproject
|
||||
#
|
||||
# For more information about the [deploy] section see:
|
||||
# https://scrapyd.readthedocs.io/en/latest/deploy.html
|
||||
|
||||
[settings]
|
||||
default = musicListdemo.settings
|
||||
|
||||
[deploy]
|
||||
#url = http://localhost:6800/
|
||||
project = musicListdemo
|
||||
Loading…
Reference in new issue