Coder Social home page Coder Social logo

wechatsogou's Introduction

基于搜狗微信搜索的微信公众号爬虫接口

项目简介

基于搜狗微信搜索的微信公众号爬虫接口,可以扩展成基于搜狗搜索的爬虫 基于Python3,但是2应该也可以使用

关于我,欢迎关注 微博:Chyroc 邮箱:[email protected]


项目使用

引用

from wechatsogou import WechatSpider
wechats = WechatSpider()
wechats.get_session()

搜索公众号 - search_gzh_info

infos = wechats.search_gzh_info(name, page)
for info in infos:
    name = info['name']

返回结果是列表,每一项均是公众号具体信息字典,具体如下

字段 含义
name 公众号名称
wechatid 公众号ID
jieshao 介绍
renzhen 认证信息,为空表示未认证
qrcode 二维码图片地址
img 头像地址
url 最近文章地址

获取公众号

对于一个已知wechatid的公众号,如果需要获取其最近文章,可以通过以下方式先获取具体信息(包括最近文章地址),然后根据``获取

detail = wechats.get_gzh_info(wechatid)
url = detail['url']

返回结果与上述search_gzh_info函数返回结果一致

获取最近文章列表字典 - get_gzh_article_dict

article_list_infos = wechats.get_gzh_article_dict(url)

article_list_infos是字典{info:{img:'',name:'',wechatid:'',jieshao:'',zhuti:''},msgdict:''}

字段 含义
info 公众号信息
info->img 头像
info->name 名称
info->wechatid id
info->jieshao 介绍
info->zhuti 主体
msgdict 具体文章信息列表
infos = article_list_infos['msgdict']['list']
for info in infos:
    comm_msg_info = info['comm_msg_info']
    app_msg_ext_info = info['app_msg_ext_info']

comm_msg_info是字典

字段 含义
status ...
fakeid ...
datetime ...
type ...
id ...
content ...

app_msg_ext_info也是字典

字段 含义
subtype ...
title 标题
copyright_stat 文章类型(100为普通,11原创,101转载)
author 作者
source_url 原文地址
fileid ...
content ...
content_url 文章地址
cover 封面图片地址
digest 描述
is_multi 是否多图文(1位多图文,有multi_app_msg_item_list字段,0为单图文)
multi_app_msg_item_list 多图文

获取最近文章列表 - get_gzh_article_detail

article_list_infos = wechats.get_gzh_article_dict(url)
item = wechats.get_gzh_article_detail(article_list_infos['msgdict'])

item是列表,每一项均是具体信息字典

字段 含义
title 标题
digest 描述
cover 封面图片地址
main 是否为一次推送中第一篇文章
content_url 文章地址
author 作者
copyright_stat 文章类型(100为普通,11原创,101转载,12?)
source_url 原文地址
fileid ...
content ...

获取文章具体信息 - get_gzh_article_info

infos = wechats.get_gzh_info('newsbro')
articledict = wechats.get_gzh_article_dict(infos['url'])
articles = wechats.get_gzh_article_detail(articledict)
for article in articles:
    article_info = wechats.get_gzh_article_info(article)

article_info是文章页具体信息字典

字段 含义
yuan 文章的固定地址(通过搜索获取的文章地址有时效性?)
content 文章内容,字典,一下三项均含img和br标签
content->content_html 原始文章内容,包括html标签及样式
content->content_rich 包含图片(包括图片应展示的样式)的文章内容
content->content_text 包含图片(<img src="..." />格式)的文章内容
comment 评论以及阅读量,字典
comment->base_resp 返回码,字典,包含下面两项
comment->base_resp->ret 返回码
comment->base_resp->errmsg 返回错误信息
comment->read_num 阅读量
comment->like_num 点赞数
comment->elected_comment_total_cnt 评论数
comment->comment 具体评论数据,每一项均是一个列表,设为comment_comment

comment_comment是一项评论

字段 含义
content 评论内容
like_num 点赞数
nick_name 评论者昵称
logo_url 评论者头像
reply 回复
其余字典未说明,请打印自行查看

获取首页推荐文章公众号最近文章地址 - get_recent_article_url_by_index_single

wechats = WechatSpider()
urls = wechats.get_recent_article_url_by_index_single(2,10) #单页
# urls = wechats.get_recent_article_url_by_index_all() #首页全部
dict = wechats.get_gzh_article_dict(url[0])

url是最近文章字典

TODO

  • 相似文章的公众号获取
  • 主页热门公众号获取
  • 文章详情页信息

wechatsogou's People

Contributors

chyroc avatar

Watchers

薛定谔的猫 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.