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. POJ1845Sumdiv题解--约数之和

    题目链接 https://cn.vjudge.net/problem/POJ-1845 分析 \(POJ\)里的数学题总是这么妙啊 首先有一个结论就是\(A=\prod{ \ {p_i}^{c_i} ...

  2. 在Pytorch上使用稀疏矩阵

    在Pytorch上使用稀疏矩阵 最近在写一个NLP的小项目,用到了Pytorch做神经网络模型.但是众所周知NLP的一个特点就是特征矩阵是稀疏矩阵,当时处理稀疏矩阵用的是scipy.sparse,现在 ...

  3. JS ES6

    变量 let 块级作用域内有效 不能重复声明 不会预处理,不存在提升 var btns = document.getElementsByTagName('button'); for (let i = ...

  4. js获取图片内容上传

    <script> $('#pic').change(function(){ var size=document.getElementById('pic').files[0].size va ...

  5. 如何处理不能新建word、excel、PPT的情况?

    Office系列办公软件是大家都非常喜欢使用的软件,但是有些朋友反映在使用电脑时,在桌面右键菜单新建选项里没有Word.Excel或PPT,非常的耽误工作. 下面就为大家介绍一下桌面右键菜单新建选项里 ...

  6. MySQL跨表更新SQL

    1 sql范式  把s表中的city_name的值设置为city表中的name,关联条件是city_code 和 code update student s, city c set s.city_na ...

  7. input checkbod 全选 反选

      <script>             var CheckBox=div.getElementsByTagName('input');                         ...

  8. new Function()语法

    函数的语法: let func = new Function(...args, body); 历史原因,参数也可以以逗号分隔的列表的形式给出,这三个意思相同: new Function('a', 'b ...

  9. string::assign

    string (1) string& assign (const string& str); substring (2) string& assign (const strin ...

  10. P4074 [WC2013]糖果公园

    思路 带修莫队+树上莫队 注意代码细节即可,答案的维护非常简单 蒟蒻的大常数代码 #include <cstdio> #include <algorithm> #include ...