import scrapy
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule from wxapp.items import WxappItem class WxSpider(CrawlSpider):
name = 'wx'
allowed_domains = ['wxapp-union.com']
start_urls = ['http://www.wxapp-union.com/portal.php?mod=list&catid=2&page=1'] rules = (
Rule(LinkExtractor(allow=r'.*mod=list&catid=2&page=\d+'), follow=True),
Rule(LinkExtractor(allow=r'.*article-.+\.html'), callback='parse_detail', follow=False),
) def parse_detail(self, response):
detail_href = response.request.url
title = response.xpath('//h1[@class="ph"]/text()').get()
content = response.xpath('//td[@id="article_content"]//text()').getall()
content = [c.strip() for c in content]
content = ''.join(content).strip()
pub_time = response.xpath('//p[@class="authors"]/span/text()').get()
author = response.xpath('//p[@class="authors"]/a/text()').get()
item = WxappItem(title=title, content=content, detail_href=detail_href, pub_time=pub_time, author=author)
yield item
from scrapy.exporters import JsonLinesItemExporter, JsonItemExporter

class WxappPipeline(object):
def __init__(self):
"""
爬虫开始的时候执行
"""
self.fp = open("data.json", 'wb')
self.exporter = JsonItemExporter(self.fp, ensure_ascii=False, encoding='utf-8') def open_spider(self, spider):
"""
爬虫开始的时候执行
:param spider:
:return:
"""
pass def process_item(self, item, spider):
self.exporter.export_item(item)
return item def close_spider(self, spider):
"""
爬虫结束的时候执行
:param spider:
:return:
"""
self.fp.close()
import scrapy

class WxappItem(scrapy.Item):
title = scrapy.Field()
content = scrapy.Field()
pub_time = scrapy.Field()
author = scrapy.Field()
detail_href = scrapy.Field()

scarpy crawl 爬取微信小程序文章的更多相关文章

  1. scarpy crawl 爬取微信小程序文章(将数据通过异步的方式保存的数据库中)

    import scrapy from scrapy.linkextractors import LinkExtractor from scrapy.spiders import CrawlSpider ...

  2. python爬取微信小程序(实战篇)

    python爬取微信小程序(实战篇) 本文链接:https://blog.csdn.net/HeyShHeyou/article/details/90452656 展开 一.背景介绍 近期有需求需要抓 ...

  3. Python爬取微信小程序(Charles)

    Python爬取微信小程序(Charles) 本文链接:https://blog.csdn.net/HeyShHeyou/article/details/90045204 一.前言 最近需要获取微信小 ...

  4. scrapy爬取微信小程序社区教程(crawlspider)

    爬取的目标网站是: http://www.wxapp-union.com/portal.php?mod=list&catid=2&page=1 目的是爬取每一个教程的标题,作者,时间和 ...

  5. 使用Python爬取微信公众号文章并保存为PDF文件(解决图片不显示的问题)

    前言 第一次写博客,主要内容是爬取微信公众号的文章,将文章以PDF格式保存在本地. 爬取微信公众号文章(使用wechatsogou) 1.安装 pip install wechatsogou --up ...

  6. 《吐血整理》高级系列教程-吃透Fiddler抓包教程(34)-Fiddler如何抓取微信小程序的包-上篇

    1.简介 有些小伙伴或者是童鞋们说小程序抓不到包,该怎么办了???其实苹果手机如果按照宏哥前边的抓取APP包的设置方式设置好了,应该可以轻松就抓到包了.那么安卓手机小程序就比较困难,不是那么友好了.所 ...

  7. 如何抓取微信小程序的源码?

    一.引言: 在工作中我们会想把别人的代码直接拿过来进行参考,当然这个更多的是前端代码的进行获取. 那么微信小程序的代码怎么样获取呢?  参考 https://blog.csdn.net/qq_4113 ...

  8. 微信小程序文章收录

    基础篇 03-04 微信登入小程序与后端实现 - 小猿取经 - 博客园 我做的小程序 - 小y - 博客园 小程序二维码和小程序带参数二维码生成 - Likwo - 博客园 accesstoken 微 ...

  9. Charles抓取微信小程序数据 以及 其它应用网站数据

    为了抓取小程序数据所以使用Charles来抓取,下面介绍下使用方法(mac环境下使用).使用Charles可以非常方便的抓取Http/Https请求.官方dmg下载地址:点击此处下载 Charles抓 ...

随机推荐

  1. IOC+EF+Core搭建项目框架(三)

    /// <summary> /// 表示类别映射配置 /// </summary> public partial class sys_UserMap : NopEntityTy ...

  2. eventFlow 系列 <二> 领域事件

    看一个聚合根: public class ExampleAggregate : AggregateRoot<ExampleAggregate, ExampleId>, IEmit<E ...

  3. js摄像头

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8& ...

  4. java八大排序代码

    import java.util.ArrayList;import java.util.List; public class FastSort { public static void main(St ...

  5. IEnumerable<T>和IQuryable<T>的区别

    https://stackoverflow.com/questions/1578778/using-iqueryable-with-linq/1578809#1578809 The main diff ...

  6. elementUI中的loading

    先安装引入 import ElementUI from 'element-ui' import { Loading } from 'element-ui' 在vue的原型链上定义一个打开loading ...

  7. ORACLE数据库 自动备份 定时计划任务 windows

    疑问为什么没有输入oracle 的数据库安装目录就能直接备份呢,可能是因为oracle默认安装c盘,在docs命令直接能操作吧,不信可以使用sqlplus试试. 一共分三步: 一.建立一个.bat 批 ...

  8. SAP CRM和C4C的内容管理(Content Management)

    SAP CRM内容管理 SAP CRM使用Attachments这个UI给用户提供内容管理的功能.通过新建按钮可以上传本地文档到CRM系统: 该内容管理支持简单的版本管理功能,用户可点击Check O ...

  9. C#遍历文件夹下的所有文件

    DirectoryInfo theFolder = new DirectoryInfo(path); DirectoryInfo[] dirInfo = theFolder.GetDirectorie ...

  10. 玩转springcloud(三):服务的提供者与调用者(注册于发现)

    一.简介 上文我们实践了cloud的注册中心的单服务于多节点的搭建,房子造好了得有人来住不是,这篇我们实践下服务提供者于调用者的案例,也就是服务端和客户端的调用. 本文会设计三个module:注册中心 ...