scrapy 爬取自己的博客
定义项目
# -*- coding: utf-8 -*-
# items.py import scrapy class LianxiCnblogsItem(scrapy.Item):
# define the fields for your item here like:
# name = scrapy.Field()
url = scrapy.Field()
title = scrapy.Field()
article = scrapy.Field()
post_date = scrapy.Field()
定义爬虫
# -*- coding: utf-8 -*-
# spider/cnblogs_spider.py from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor from lianxi_cnblogs.items import LianxiCnblogsItem class MininovaSpider(CrawlSpider): name = 'cnblogs'
allowed_domains = ['cnblogs.com']
start_urls = ['http://www.cnblogs.com/hhh5460/default.html?page=%s' i+1 for i in range(11)] # 分页
rules = [Rule(LinkExtractor(allow=['/p/\d+\.html']), 'parse_cnblogs')] def parse_cnblogs(self, response):
res = LianxiCnblogsItem()
res['url'] = response.url
res['title'] = response.xpath("//h1/a/text()").extract()
res['article'] = response.xpath("//div[@id=topics]").extract()
res['post_date'] = response.xpath("//span[@id='post-date']/text()").extract()
return res
运行爬虫
$ scrapy crawl cnblogs -o results.json
scrapy 爬取自己的博客的更多相关文章
- Scrapy爬取自己的博客内容
python中常用的写爬虫的库有urllib2.requests,对于大多数比较简单的场景或者以学习为目的,可以用这两个库实现.这里有一篇我之前写过的用urllib2+BeautifulSoup做的一 ...
- Python爬虫小实践:爬取任意CSDN博客所有文章的文字内容(或可改写为保存其他的元素),间接增加博客访问量
Python并不是我的主业,当初学Python主要是为了学爬虫,以为自己觉得能够从网上爬东西是一件非常神奇又是一件非常有用的事情,因为我们可以获取一些方面的数据或者其他的东西,反正各有用处. 这两天闲 ...
- 开发记录_自学Python写爬虫程序爬取csdn个人博客信息
每天刷开csdn的博客,看到一整个页面,其实对我而言,我只想看看访问量有没有上涨而已... 于是萌生了一个想法: 想写一个爬虫程序把csdn博客上边的访问量和评论数都爬下来. 打算通过网络各种搜集资料 ...
- python+selenium+requests爬取我的博客粉丝的名称
爬取目标 1.本次代码是在python2上运行通过的,python3的最需改2行代码,用到其它python模块 selenium 2.53.6 +firefox 44 BeautifulSoup re ...
- python3+selenium3+requests爬取我的博客粉丝的名称
爬取目标 1.本次代码是在python3上运行通过的 selenium3 +firefox59.0.1(最新) BeautifulSoup requests 2.爬取目标网站,我的博客:https:/ ...
- step2: 爬取廖雪峰博客
#https://zhuanlan.zhihu.com/p/26342933 #https://zhuanlan.zhihu.com/p/26833760 scrapy startproject li ...
- 一文搞定scrapy爬取众多知名技术博客文章保存到本地数据库,包含:cnblog、csdn、51cto、itpub、jobbole、oschina等
本文旨在通过爬取一系列博客网站技术文章的实践,介绍一下scrapy这个python语言中强大的整站爬虫框架的使用.各位童鞋可不要用来干坏事哦,这些技术博客平台也是为了让我们大家更方便的交流.学习.提高 ...
- scrapy爬取极客学院全部课程
# -*- coding: utf-8 -*- # scrapy爬取极客学院全部课程 import scrapy from pyquery import PyQuery as pq from jike ...
- Scrapy爬取美女图片第四集 突破反爬虫(上)
本周又和大家见面了,首先说一下我最近正在做和将要做的一些事情.(我的新书<Python爬虫开发与项目实战>出版了,大家可以看一下样章) 技术方面的事情:本次端午假期没有休息,正在使用fl ...
随机推荐
- Swift开发第三篇——Playground
本篇分为两部分: 一.Playground的延时运行 二.Playground的可视化 一.Playground的延时运行 Playground 就是提供一个可以即时编译的类似 REPL 的环境,他为 ...
- android 隐藏标题栏
在onCreate()方法中添加如下代码: public class FirstActivity extends Activity { @Override protected void onCreat ...
- android 进程/线程管理(四)续----消息机制的思考(自定义消息机制)
继续分析handler 和looper 先看看handler的 public void dispatchMessage(Message msg) { if (msg.callback != null) ...
- Python文件操作之简化代码
一朝误入此门中,从此红尘了如空.... 程序这条路,当真是路漫漫... 这两天找到一本书,名为<笨方法学Python第三版>,全实例,感觉挺好的.需要的点书名下载, 密码:gmpn 今天想 ...
- Effective Java 25 Prefer lists to arrays
Difference Arrays Lists 1 Covariant Invariant 2 Reified at runtime Erased at run time 3 Runtime type ...
- JavaScript Patterns 3.2 Custom Constructor Functions
When you invoke the constructor function with new, the following happens inside the function: • An e ...
- JavaScript Patterns 2.9 Coding Conventions
It’s important to establish and follow coding conventions—they make your code consistent, predictabl ...
- cmd常用命令 和 sql server相关基础
在Java开发中 ms sql server 接触算是比较少的,本文记录一些ms sql server的基础知识. 1. 为表字段增加索引:create index user_openid on us ...
- cxf 消息寻址
一.消息寻址 WS-Addressing是将消息路由数据包含在SOAP头中的一种标准方法.利用WS-Addressing的消息可以在标准化的SOAP头中包含自己的包含发送元数据,而不是依赖于网络层传输 ...
- MyCat 学习笔记 第六篇.数据分片 之 按月数据分片
1 应用场景 Mycat 有很多数据分库规则,接下来几篇就相关觉得常用的规则进行试用与总结. 一般来说,按自然月份来进行数据分片的规则比较适用于商城订单查询,类似最近1周.2周.3个月内的数据.或是报 ...