使用Scrapy框架,爬取b站番剧信息。

感觉好久没写爬虫的,今天看了在b站浏览了一会儿,发现b站有很多东西可以爬取的,比如首页的排行榜,番剧感觉很容易找到数据来源的,所以就拿主页的番剧来练练手的。

爬取的网址:
https://www.bilibili.com/anime/index/#season_version=-1&area=-1&is_finish=-1&copyright=-1&season_status=-1&season_month=-1&year=-1&style_id=-1&order=3&st=1&sort=0&page=1*


通过观察url的规律,去除一些不影响请求网站的url中的数据,得到url
https://api.bilibili.com/pgc/season/index//resultpage=1&season_type=1&pagesize=20&type=1,然后发现只需每次改变page=的值就可以得到想要的信息,page最大值为153,感觉这次爬取的信息作用不大,不过还是把代码写出来了

运行scrapy的main方法,无需每次scrapy crawl name

# -*- coding: utf-8 -*-
#@Project filename:PythonDemo  dramaMain.py
#@IDE   :IntelliJ IDEA
#@Author :ganxiang
#@Date   :2020/03/02 0002 19:16from scrapy.cmdline import execute
import os
import syssys.path.append(os.path.dirname(os.path.abspath(__file__)))
execute(['scrapy','crawl','drama'])

编写的dramaSeries.py

# -*- coding: utf-8 -*-
import scrapy
import json
from ..items import DramaseriesItem
class DramaSpider(scrapy.Spider):name = 'drama'allowed_domains = ['https://api.bilibili.com/']i =1start_urls = ['https://api.bilibili.com/pgc/season/index//result?page=%s&season_type=1&pagesize=20&type=1'% s for s in range(1,101)]def parse(self, response):item =DramaseriesItem()drama =json.loads(response.text)data =drama['data']data_list =data['list']# print(data_list)for filed in data_list:item['number']=self.iitem['badge']=filed['badge']item['cover_img']=filed['cover']item['index_show']=filed['index_show']item['link']=filed['link']item['media_id']=filed['media_id']item['order_type']=filed['order_type']item['season_id']=filed['season_id']item['title']=filed['title']print(self.i,item)self.i+=1yield itemself.i+=20

items.py

# -*- coding: utf-8 -*-# Define here the models for your scraped items
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.htmlimport scrapyclass DramaseriesItem(scrapy.Item):# define the fields for your item here like:# name = scrapy.Field()number =scrapy.Field()badge =scrapy.Field()cover_img =scrapy.Field()index_show =scrapy.Field()link =scrapy.Field()media_id =scrapy.Field()order_type =scrapy.Field()season_id =scrapy.Field()title =scrapy.Field()pass

pipelines.py

# -*- coding: utf-8 -*-# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html
from openpyxl import Workbook
from scrapy.utils.project import get_project_settings
settings = get_project_settings()class DramaseriesPipeline(object):excelBook =Workbook()activeSheet =excelBook.activefile =['number','title','link','media_id','season_id','index_show','cover_img','badge']activeSheet.append(file)def process_item(self, item, spider):files =[item['number'],item['title'],item['link'],item['media_id'],item['season_id'],item['index_show'],item['cover_img'],item['badge']]self. activeSheet.append(files)self.excelBook.save('./drama.xlsx')return item

settings.py
打开

# Obey robots.txt rules
ROBOTSTXT_OBEY = 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',
}
ITEM_PIPELINES = {'dramaSeries.pipelines.DramaseriesPipeline': 300,
}

运行结果爬取了两千多字段,其实还可以爬很多的。


使用Scrapy框架,爬取b站番剧信息。相关推荐

  1. scrapy框架----爬取B站番剧弹幕

    items.py文件 定义要爬取的数据的字段 import scrapy class bilidanmu(scrapy.Item):danmu = scrapy.Field() #弹幕cid = sc ...

  2. python爬取B站番剧索引页面并保存文本和图片

    该篇文章为"行路难=_="原创 期末的Python考试要写一个爬取网站信息的程序,我就选取了b站番剧索引页面作为目标网页(因为感觉番剧主页的信息太杂了.) 目标网页:https:/ ...

  3. datetime 索引_Python爬取B站番剧索引页面并保存文本和图片

    期末的Python考试要写一个爬取网站信息的程序,我就选取了b站番剧索引页面作为目标网页(因为感觉番剧主页的信息太杂了.) 目标网页:https://www.bilibili.com/anime/in ...

  4. 小福利,带你使用scrapy框架爬取苏宁图书海量信息

    大家好,我是天空之城,今天给大家带来小福利,带你使用scrapy框架爬取苏宁图书海量信息 下图为项目的目录结构 看下最后的数据截图,可以存为excel文件,也可以存入mysql数据库,参见前面文章介绍 ...

  5. 爬虫练习四:爬取b站番剧字幕

    由于个人经常在空闲时间在b站看些小视频欢乐一下,这次就想到了爬取b站视频的弹幕. 这里就以番剧<我的妹妹不可能那么可爱>第一季为例,抓取这一番剧每一话对应的弹幕. 1. 分析页面 这部番剧 ...

  6. python中scrapy可以爬取多少数据_python scrapy框架爬取某站博人传评论数据

    1. B站博人传评论数据爬取简介 今天想了半天不知道抓啥,去B站看跳舞的小姐姐,忽然看到了评论,那就抓取一下B站的评论数据,视频动画那么多,也不知道抓取哪个,选了一个博人传跟火影相关的,抓取看看.网址 ...

  7. 利用Scrapy框架爬取LOL皮肤站高清壁纸

    利用Scrapy框架爬取LOL皮肤站高清壁纸  Lan   2020-03-06 21:22   81 人阅读  0 条评论 成品打包:点击进入 代码: 爬虫文件 # -*- coding: utf- ...

  8. scrapy获取a标签的连接_python爬虫——基于scrapy框架爬取网易新闻内容

    python爬虫--基于scrapy框架爬取网易新闻内容 1.需求[前期准备] 2.分析及代码实现(1)获取五大板块详情页url(2)解析每个板块(3)解析每个模块里的标题中详情页信息 点击此处,获取 ...

  9. 利用python的scrapy框架爬取google搜索结果页面内容

    scrapy google search 实验目的 爬虫实习的项目1,利用python的scrapy框架爬取google搜索结果页面内容. https://github.com/1012598167/ ...

最新文章

  1. 【学习笔记】超简单的多项式求逆(含全套证明)
  2. SpringMVC必备的jar包
  3. centos 6.5内核升级
  4. Keil插件推荐及使用教程
  5. JavaScript --- 表单focus,blur,change事件的实现
  6. .net core 实现基于 JSON 的多语言
  7. java主流微服务框架_Spring Boot作为当下最流行的微服务开发框架,一名合格的Java开发者一定有所了解,...
  8. 学术会议 | 中国杭州举办——第21届国际语义网大会​ISWC2022 Call for Papers
  9. 进入 App Store 打分
  10. python输出用逗号隔开的数字_Python:从字符串中提取带有点和逗号的数字
  11. IntelliJ Idea学习笔记004--- idea修改格式化代码快捷键_顺带一个激活地址_以及常用快捷键
  12. 吴恩达深度学习编程作业:TensorFlow
  13. ESP32+st7789/ili9341运行LVGL例程,依赖ESP-IDF编译lv_port_esp32官方Demo(1)
  14. java 控制路由器_停用角度路由器链路
  15. Altium Designer 18安装教程
  16. 项目管理 : 智能家居项目实施计划
  17. 《视觉SLAM十四讲》详细笔记
  18. 也不能在你喝醉的时候假装很生气的臭骂一顿
  19. MakeFile入门详解
  20. c语言一个小写字母字节,C语言:给定一个小写字母,转换成大写字母

热门文章

  1. 关于python中的复数、下列说法正确的是_关于Python中的复数,下列说法正确的是?...
  2. (一)基于区块链的自动抽奖系统从0到1实现
  3. windows系统通过命令行方式修改多字符串值类型的注册表
  4. 小写数字与大写数字转换
  5. 小甲鱼28课文件:因为懂你,总结反思
  6. 关键词指数是什么意思?
  7. 长尾关键词是什么意思? 1
  8. Eclipse 国内镜像下载
  9. 使用几何光学实现空间相对定位(python+opencv)
  10. 振动位移传感器IEPE加速度3轴采集模块