1. 程式人生 > >python3 scrapy爬取微信公眾號及歷史資訊V2.0

python3 scrapy爬取微信公眾號及歷史資訊V2.0

程式碼部分,日後補充:

# -*- coding: utf-8 -*-
# @Time    : 2018/2/25 14:24
# @Author  : 蛇崽
# @Email   : [email protected]
# @File    : WeChatSogou.py(微信公眾號爬蟲:不包含瀏覽量跟評論)
import scrapy
import re
import time
import json
import requests
from fake_useragent import UserAgent
from scrapy import Request
from scrapy_redis.spiders import
RedisSpider from News_scrapy.items import NewsItem from News_scrapy.constants.WeChatSource import WXSource class WeChatSogouSpider(scrapy.Spider): name = "WeChatAiWeiBang" allowed_domains = ["aiweibang.com", 'mp.weixin.qq.com'] start_urls = ['http://top.aiweibang.com/user/search_advanced'
] def parse(self, response): wx_source = WXSource.get_dict() for v_wx_source in wx_source: try: type = v_wx_source.split('-')[0] channel = v_wx_source.split('-')[1] print("正在抓取:", type, channel) url = 'http://top.aiweibang.com/user/search?kw={}'
.format(channel) yield scrapy.Request(url=url,callback=self.get_target_gzh,meta={'type':type,'channel':channel}) except: continue print('wx_source error ===', v_wx_source) def get_target_gzh(self,response): print('get_target_gzh == ',response) type = response.meta['type'] channel = response.meta["channel"] gzh_url = 'http://top.aiweibang.com/user/getsearch' formdata = {'PageIndex': '1', 'PageSize': '10', 'Kw': channel} yield scrapy.FormRequest(url=gzh_url,callback=self.get_v_gzh,formdata=formdata,meta={'type':type,'channel':channel}) def get_v_gzh(self,response): print('get_v_gzh jsondata === ',response.body) type = response.meta['type'] channel = response.meta["channel"] jsondatas = json.loads(str(response.body.decode('utf-8'))) first_gzh_Id = jsondatas['data']['data'][0]['Id'] print('first_gzh_ID ==== ',first_gzh_Id) if first_gzh_Id: gzh_url = 'http://top.aiweibang.com/article/{}'.format(first_gzh_Id) yield scrapy.Request(url=gzh_url,callback=self.get_article_gzh,meta={'type':type,'channel':channel,'gzh_ID':first_gzh_Id}) def get_article_gzh(self,response): print('get_article_gzh === ',response.body) type = response.meta['type'] channel = response.meta["channel"] gzh_ID = response.meta["gzh_ID"] # 獲取全部文章列表的url all_url = 'http://top.aiweibang.com/article/getarticles' formadata = {'PageIndex': '1', 'PageSize': '20', 'Type': '0', 'Wechat': gzh_ID} yield scrapy.FormRequest(url=all_url,formdata=formadata,callback=self.get_all_article,meta={'type':type,'channel':channel,'gzh_ID':gzh_ID}) def get_all_article(self,response): print('get_all_article ***** the last *** ',response) type = response.meta['type'] channel = response.meta["channel"] jsondatas = json.loads(str(response.body.decode('utf-8'))) # 獲取拼接aid aids = jsondatas['data']['data'] for aid in aids: print('aid -- ',aid) v_aid = aid['Id'] print('v_aid ',v_aid) if v_aid: detail_url = 'http://top.aiweibang.com/article/url?aid={}'.format(v_aid) yield scrapy.Request(url=detail_url,callback=self.get_wx_url,meta={'type':type,'channel':channel}) def get_wx_url(self,response): print('get_wx_url ----- ',response) print('wx_url 00000000000 ',response.url)

相關推薦

python3 scrapy公眾歷史資訊V2.0

程式碼部分,日後補充: # -*- coding: utf-8 -*- # @Time : 2018/2/25 14:24 # @Author : 蛇崽 # @Email : [email protected] # @File

python3 scrapy公眾歷史資訊V1.0

環境: python3 scrapy 目的 寫這篇文章主要是做一下紀念,畢竟是搞了快兩天的東西了,今天加大了量,使用scrapy爬取100多個微信公眾號,然後出現IP被封的情況下,當然了,這種情況並不是沒有辦法解決,只需要在scr

python 多線程方法公眾文章

微信爬蟲 多線程爬蟲 本文在上一篇基礎上增加多線程處理(http://blog.51cto.com/superleedo/2124494 )執行思路:1,規劃好執行流程,建立兩個執行線程,一個控制線程2,線程1用於獲取url,並寫入urlqueue隊列3,線程2,通過線程1的url獲取文章內容,並保

PK10平臺開發與用python公眾文章

網址 谷歌瀏覽器 pytho google http 開發 微信 安裝python rom 本文通過微信提供微信PK10平臺開發[q-21528-76294] 網址diguaym.com 的公眾號文章調用接口,實現爬取公眾號文章的功能。註意事項 1.需要安裝python s

Python公眾歷史文章進行資料分析

思路: 1. 安裝代理AnProxy,在手機端安裝CA證書,啟動代理,設定手機代理; 2. 獲取目標微信公眾號的__biz; 3. 進入微信公眾號的歷史頁面; 4. 使用Monkeyrunner控制滑屏;獲取更多的歷史訊息; 5. 記錄文章標題,摘要,建立時間,創作型別,地

使用anyproxy+安卓模擬器自動公眾資料-包括閱讀數和點贊數

本文並非作者原創,本文來自 zsyoung 的CSDN 部落格 ,全文地址請點選:https://blog.csdn.net/zsyoung/article/details/78849982?utm_source=copy 在這裡只是把相關步驟清晰明化一下: 1.安裝node.js &n

【Python爬蟲】公眾文章資訊準備工作

有一天發現我關注了好多微信公眾號,那時就想有沒有什麼辦法能夠將微信公眾號的文章弄下來,而且還想將一些文章的精彩評論一起搞下來。參考了一些文章,通過幾天的研究基本上實現了自己的要求,現在記錄一下自己的一些心得。 整個研究過程如下: 1.瞭解微信公眾號文章連結的組成,歷史文章API組成,單個文章

用python公眾文章

本文通過微信提供的公眾號文章呼叫介面,實現爬取公眾號文章的功能。 # -*- coding: utf-8 -*- from selenium import webdriver import time import json import reques

公眾

1.抓取公眾號歷史記錄 首先利用Fiddler4抓包,監聽手機流量 .手機電腦連線同一網路,手機需設定代理,伺服器為電腦ip,埠號為8888,fiddler也需要設定,不會百度看看 點選手機公眾號“檢視歷史訊息”。注意fiddler抓的請求 , 第二個即為歷史訊息那個請求,

記一次企業級爬蟲系統升級改造(四):公眾文章(通過搜狗與新榜等第三方平臺)

首先表示抱歉,年底大家都懂的,又涉及SupportYun系統V1.0上線。故而第四篇文章來的有點晚了些~~~對關注的朋友說聲sorry! SupportYun系統當前一覽:   首先說一下,文章的進度一直是延後於系統開發進度的。   當前系統V1.0 已經正式上線服役了,這

輿情監控系統——step1.公眾文章

小明醬於2018年元旦更新,寫的還是很糙,如果你在爬蟲問題中遇到問題,歡迎交流哦,評論區隨時為你開放! 實習兩週過去了,目前任務量還不是很大。我的老闆很nice,是個軍校生,給我安排的任務也比我預想的要貼近我的研究方向,做的是微信公眾號文章的輿情監控系統,以下

php利用curl爬蟲公眾,防止ip封鎖

前段時間遇到一個需求,是定向抓取一批微信公眾號,於是找到了搜狗搜尋引擎比較好,下面貼出原始碼,各位可以試下 public function test(){ //搜狗抓取微信公眾號 $url="http://weixin.sogou.com/weixin?type=1&

公眾內容——繪製詞雲

寫在前面的話 前段時間寫了一篇通過搜狗引擎獲取微信公眾號的文章,最近又看了一個網易雲歌詞繪製詞雲的程式然後我就想,能否把這兩者結合起來呢還好經歷幾多波折終於把這個東西給弄出來了。其實中間的實現不是很難, 關鍵是環境搭建實在是太困難了好了,先把程式碼以及效果圖奉

pythom公眾最新部分文章(可執行程式碼)

執行下面的程式碼需要安裝以下內容: pip install pyquery pip install requests pip install selenium pip install pyExcelerator pip install

python使用webdriver公眾資訊

# -*- coding: utf-8 -*- from selenium import webdriver import time import json import requests import re import random #微信公眾號賬號 user=""

python爬蟲(17)出新高度_抓公眾文章(selenium+phantomjs)(上)

抓取微信公眾號的文章 一.思路分析 目前所知曉的能夠抓取的方法有: 1、微信APP中微信公眾號文章連結的直接抓取(http://mp.weixin.qq.com/s?__biz=MjM5MzU4ODk2MA==&mid=2735446906&idx=1&am

python爬蟲(17)出新高度_抓公眾文章(selenium+phantomjs)(下)(windows版本)

前兩天在linux 上面寫了一版爬取微信公眾號的文章 今天重新修改一下,讓它在windows上面也能執行 執行下面的程式碼需要安裝以下內容: pip install pyquery pip install requests pip install selenium

python通過手機抓公眾

使用 Fiddler 抓包分析公眾號 開啟微信隨便選擇一個公眾號,檢視公眾號的所有歷史文章列表    在 Fiddler 上已經能看到有請求進來了,說明公眾號的文章走的都是HTTPS協議,這些請求就是微信客戶端向微信伺服器傳送的HTTP請求。 模擬微信請求  1

利用搜狗抓公眾文章

微信一直是一個自己玩的小圈子,前段時間搜狗推出的微信搜尋帶來了一絲曙光。搜狗搜尋推出了內容搜尋和公眾號搜尋兩種,利用後者可以抓取微信公眾號的最新內容,看了下還是比較及時的。 每個公眾號都有一個openid,最早可以直接利用http://weixin.sogou

春哥教你支付商戶如何綁定多個公眾小程序

img 線下 tex 如何 創建 微信公眾 實現 alt mark 大家在使用微信支付的時候都知道微信支付賬號要和對應的公眾號、小程序有對應的綁定關系才可以使用的。今天春哥技術博客就給大家總結一下這方面的知識。 背景 微信支付交易發起依賴於公眾號、小程序、移動應用(即A