爬虫Scrapy框架-2爬取网站视频详情
爬取视频详情:http://www.id97.com/
创建环境:



movie.py 爬虫文件的设置:
# -*- coding: utf-8 -*-
import scrapy from moviePro.items import MovieproItem
class MovieSpider(scrapy.Spider):
name = 'movie'
# allowed_domains = ['www.id97.com']
start_urls = ['http://www.id97.com/'] def secondPageParse(self,response):
item = response.meta['item']
item['actor']=response.xpath('/html/body/div[1]/div/div/div[1]/div[1]/div[2]/table/tbody/tr[1]/td[2]/a/text()').extract_first()
item['show_time'] = response.xpath('/html/body/div[1]/div/div/div[1]/div[1]/div[2]/table/tbody/tr[7]/td[2]/text()').extract_first() yield item def parse(self, response): div_list=response.xpath('/html/body/div[1]/div[2]/div[1]/div/div')
for div in div_list:
item = MovieproItem() item['name']=div.xpath('./div/div[@class="meta"]//a/text()').extract_first()
#类型下面有多个a标签,所以使用//text,另外取到的是多个值,所以就用extract取值
item['kind']=div.xpath('./div/div[@class="meta"]/div[@class="otherinfo"]//text()').extract() #拿到的是列表类型,要转为字符串类型 item['kind'] = ''.join(item['kind'])
#拿到二次连接,用于发请求,拿到电影详细的描述信息
item['url'] = div.xpath('./div/div[@class="meta"]//a/@href').extract_first() #将item对象参给二级页面方法,进而将内容存入到item里面
yield scrapy.Request(url=item['url'],callback=self.secondPageParse,meta={'item':item})
items.py里面的设置:
# -*- coding: utf-8 -*- # Define here the models for your scraped items
#
# See documentation in:
# https://doc.scrapy.org/en/latest/topics/items.html import scrapy class MovieproItem(scrapy.Item):
# define the fields for your item here like:
# name = scrapy.Field()
name=scrapy.Field()
kind=scrapy.Field()
url=scrapy.Field()
actor=scrapy.Field()
show_time=scrapy.Field()
pipelines.py管道里面设置:
# -*- coding: utf-8 -*- # Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
import json class MovieproPipeline(object):
def process_item(self, item, spider):
dic_item={
'电影名字':item['name'],
'影片类型':item['kind'],
'主演':item['actor'],
'上映时间':item['show_time'], } json_str=json.dumps(dic_item,ensure_ascii=False)
with open('./movie_des.json','at',encoding='utf-8') as f:
f.write(json_str)
print(item['name'])
return item
日志等级设置:

手动设置日志等级,在settings里面设置(可以写在任意位置)

将制定日志信息,写入到文件中进行存储:

爬虫Scrapy框架-2爬取网站视频详情的更多相关文章
- Scrapy框架——CrawlSpider爬取某招聘信息网站
CrawlSpider Scrapy框架中分两类爬虫,Spider类和CrawlSpider类. 它是Spider的派生类,Spider类的设计原则是只爬取start_url列表中的网页, 而Craw ...
- python爬虫:爬取网站视频
python爬取百思不得姐网站视频:http://www.budejie.com/video/ 新建一个py文件,代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 ...
- scrapy框架来爬取壁纸网站并将图片下载到本地文件中
首先需要确定要爬取的内容,所以第一步就应该是要确定要爬的字段: 首先去items中确定要爬的内容 class MeizhuoItem(scrapy.Item): # define the fields ...
- scrapy框架 + selenium 爬取豆瓣电影top250......
废话不说,直接上代码..... 目录结构 items.py import scrapy class DoubanCrawlerItem(scrapy.Item): # 电影名称 movieName = ...
- 爬虫--scrapy+redis分布式爬取58同城北京全站租房数据
作业需求: 1.基于Spider或者CrawlSpider进行租房信息的爬取 2.本机搭建分布式环境对租房信息进行爬取 3.搭建多台机器的分布式环境,多台机器同时进行租房数据爬取 建议:用Pychar ...
- python爬取网站视频保存到本地
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: Woo_home PS:如有需要Python学习资料的小伙伴可以加点 ...
- Scrapy爬虫框架之爬取校花网图片
Scrapy Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 其可以应用在数据挖掘,信息处理或存储历史数据等一系列的程序中.其最初是为了页面抓取 (更确切来说, 网络抓取 )所设 ...
- python爬虫入门10分钟爬取一个网站
一.基础入门 1.1什么是爬虫 爬虫(spider,又网络爬虫),是指向网站/网络发起请求,获取资源后分析并提取有用数据的程序. 从技术层面来说就是 通过程序模拟浏览器请求站点的行为,把站点返回的HT ...
- 使用scrapy爬取网站的商品数据
目标是爬取网站http://www.muyingzhijia.com/上全部的商品数据信息,包括商品的一级类别,二级类别,商品title,品牌,价格. 搜索了一下,python的scrapy是一个不错 ...
随机推荐
- shareTo 网页版分享
// share -------- var shareTo = function (dest, shareCode) { var appKey = "1667889534"; // ...
- 【Python图像特征的音乐序列生成】第一阶段的任务分配
从即日起到7月20号,项目成员进行了第一次任务分配. 赵同学A.岳同学.周同学,负责了图像数据的情感数据集制作,他们根据自己的经验,对图像进行了情绪提取. 赵同学B全权负责向量映射这一块的网络搭建. ...
- python爬虫之路——初识爬虫三大库,requests,lxml,beautiful.
三大库:requests,lxml,beautifulSoup. Request库作用:请求网站获取网页数据. get()的基本使用方法 #导入库 import requests #向网站发送请求,获 ...
- connect() to 192.168.30.71:8082 failed (99: Cannot assign requested address) while connecting to upstream, client: 114.80.182.136, server: localhost, request: "GET /home/senior HTTP/1.1", upstream: "
connect() to 192.168.30.71:8082 failed (99: Cannot assign requested address) while connecting to ups ...
- RAC数据库后台进程介绍
在RAC数据库上会比单实例数据库多一些进程,这些进程是RAC特有的,为了实现集群数据库功能而设置的. 10g RAC特有进程:$ ps -ef|grep ora_oracle 4721 ...
- 多并发下 SimpleDateFormat 出现错误
private static String time = "2019-01-11 11:11:11"; private static long timestamp = 154717 ...
- CPP-基础:新标准 C++iostream
在新的标准 C++ iostream 库中: 1. open 函数不采用第三个参数(保护参数). 2. 无法从文件句柄创建流. 3. 除了几个例外,新的标准 C++ 库中的所有名称都在 std 命名空 ...
- C++调用C语言编译的so文件
参考链接:https://blog.csdn.net/chenjinlong126/article/details/78990350 一.制作so文件:libadd_c.so或libadd_cpp.s ...
- 7.Props向子组件传递数据
组件实例的作用域是孤立的.这意味着不能并且不应该在子组件的模板内直接引用父组件的数据. 可以使用 props 把数据传给子组件. for-child-msg="aaa" , fo ...
- HTML5 跨文档消息传输
对窗口对象的message事件进行监听 window.addEventListener("message", function(event) { // 处理程序代码 }, fals ...