获取文章内容 - deal_article_content
article_content = wechats.deal_article_content(text=text) # 或 article_content = wechats.deal_article_content(url=url)
text是文章页文本,url是文章页链接
返回是文章内容(含有html格式)
Api for wechat mp with sogou
基于搜狗微信搜索的微信公众号爬虫接口,可以扩展成基于搜狗搜索的爬虫
如果有问题,请提issue
132955136
甲鱼说,咖啡是灵魂的饮料,买点咖啡
谢谢:
[微信] [ax4] [50]
[微信] [风雨坛·君] [50]
[支付宝] [陆小凤] [28.88]
[支付宝] [朋鑫] [18.88]
[微信] [JenkinsY94] [9.99]
[微信] [谁认领一下] [8]
[微信] [谁认领一下] [1]
Q:没有得到原始文章url? A:微信屏蔽此接口,请在临时链接有效期内保存文章内容。 Q:获取文章只能10篇? A:是的,仅显示最近10条群发。 Q:使用的是python 2 还是 3? A:都支持,若出错,请报BUG。
参见test.py
pip install wechatsogou
import logging
import logging.config
logging.config.fileConfig('logging.conf')
logger = logging.getLogger()
from wechatsogou import * wechats = WechatSogouApi()
name = '南京航空航天大学' wechat_infos = wechats.search_gzh_info(name)
返回结果是列表,每一项均是公众号具体信息字典,具体如下
字段 |
含义 |
|---|---|
name |
公众号名称 |
wechatid |
公众号ID |
jieshao |
介绍 |
renzhen |
认证信息,为空表示未认证 |
qrcode |
二维码图片地址 |
img |
头像地址 |
url |
最近文章地址 |
post_perm |
月发文篇数 |
read_count |
平均阅读 |
对于一个已知wechatid的公众号
wechat_id = 'nanhangqinggong' wechat_info = wechats.get_gzh_info(wechat_id)
返回结果与上述search_gzh_info返回结果一致
keywords = '傅里叶变换' wechat_articles = wechats.search_article_info(keywords)
返回结果是列表,每一项均是文章信息字典,具体如下
字段 |
含义 |
|---|---|
name |
文章标题 |
url |
文章链接 |
img |
文章封面图片缩略图,可转为高清大图 |
zhaiyao |
文章摘要 |
time |
文章推送时间,10位时间戳 |
gzhname |
公众号名称 |
gzhqrcodes |
公众号二维码 |
gzhurl |
公众号最近文章地址 |
data = wechats.get_gzh_message(url=url) # 或者 data = wechats.get_gzh_message(wechatid=wechatid) # 或者(不推荐) data = wechats.get_gzh_message(wechat_name=wechat_name)
返回的是 列表,每一项均是字典,一定含有字段qunfa_id,datetime,type
字段 |
含义 |
|---|---|
qunfa_id |
群发消息id |
datetime |
群发10位时间戳 |
type |
群发消息类型 |
下面是type不同的值时的其他字段
字段 |
含义 |
|---|---|
type |
1,表示文字 |
content |
文字内容 |
字段 |
含义 |
|---|---|
type |
3,表示图片 |
img_url |
图片链接 |
字段 |
含义 |
|---|---|
type |
34,表示音频 |
play_length |
长度 |
fileid |
id |
audio_src |
音频地址 |
字段 |
含义 |
|---|---|
type |
49,表示图文 |
main |
是否是一次推送中第一篇文章,1则是 |
is_multi |
本图文所属推送是否是多图文 |
title |
文章标题 |
digest |
摘要 |
fileid |
id |
content_url |
文章地址 |
source_url |
原文地址 |
cover |
封面图片 |
author |
作者 |
copyright_stat |
文章内容版权性 |
字段 |
含义 |
|---|---|
type |
62,表示视频 |
cdn_videoid |
id |
thumb |
缩略图 |
video_src |
视频地址 |
data = wechats.get_gzh_message_and_info(url=url) # 或者 data = wechats.get_gzh_message_and_info(wechatid=wechatid) # 或者(不推荐) data = wechats.get_gzh_message_and_info(wechat_name=wechat_name)
返回的是字典{‘gzh_info’:gzh_info, ‘gzh_messages’:gzh_messages}
字段 |
含义 |
|---|---|
gzh_info |
公众号信息字典 |
gzh_messages |
群发消息列表 |
其中gzh_info的具体如下
字段 |
含义 |
|---|---|
name |
公众号名称 |
wechatid |
公众号id |
jieshao |
介绍 |
renzhen |
认证,为空表示未认证 |
qrcode |
二维码 |
img |
头像图片 |
url |
最近文章地址 |
gzh_messages一定含有字段qunfa_id,datetime,type 具体见上一项
article_content = wechats.deal_article_content(text=text) # 或 article_content = wechats.deal_article_content(url=url)
text是文章页文本,url是文章页链接
返回是文章内容(含有html格式)
article_comment = wechats.deal_article_comment(text=text) # 或 article_comment = wechats.deal_article_comment(url=url)
text是文章页文本,url是文章页链接
一般需要处理,因为需要在这一步获取固定的而不是临时的文章链接
article_info = wechats.deal_article(url)
返回字典,具体如下
字段 |
含义 |
|---|---|
yuan |
文章固定地址 |
related |
相似文章信息字典 |
comment |
评论信息字典 |
content_html |
文章内容 |
comment是评论以及阅读量,字典
字段 |
含义 |
|---|---|
base_resp |
返回码,字典,包含下面两项 |
base_resp->ret |
返回码 |
base_resp->errmsg |
返回错误信息 |
read_num |
阅读量 |
like_num |
点赞数 |
elected_comment_total_cnt |
评论数 |
comment |
具体评论数据,每一项均是一个列表,设为comment_comment |
comment_comment是一项评论
字段 |
含义 |
|---|---|
content |
评论内容 |
like_num |
点赞数 |
nick_name |
评论者昵称 |
logo_url |
评论者头像 |
reply |
回复 |
其余字典未说明,请打印自行查看 |
… |
articles_single = wechats.get_recent_article_url_by_index_single()
返回的是列表,每一项是不同公众号的的最近文章页
articles_all = wechats.get_recent_article_url_by_index_all()
返回的是列表,每一项是不同公众号的的最近文章页
sugg_keyword = wechats.get_sugg('中国梦')
返回的是列表,每一项是不同公众号的的最近文章页
[x] 相似文章的公众号获取
[x] 主页热门公众号获取
[x] 文章详情页信息
[x] 所有类型的解析
[x] 验证码识别
[ ] 接入爬虫框架
[x] 兼容py2
Closed issues:
pip 安装 No module named requests 什么情况 #59
微信搜索公众号结果模版改变了 #51
ImportError: cannot import name config #40
Merged pull requests:
Closed issues:
引入模块的时候报错 #33
导入文件后有bug #31
请问如何设置代理 #27
请问最近搜狗返回的Html内容是改了吗?最近抓内容出错。 #25
结果模版更新了 #24
文章标题带引号(”,")的情况解析报错 #23
请问,我运行test.py时为何没报错却没得到任何结果? #21
如何获得公众号的id和名称? #20
search_gzh_info无法取得内容 #18
原始文章url #17
请问在Linux下可以使用吗?我运行了一下出现如下问题,还望指教 #16
log怎么使用? #15
抓取数据有时成功,有时失败 #14
验证码打开失败问题原因是: #13
验证码输入后失败 #12
获得的文章链接,如果打开需要验证码输入才跳转 #11
获取文章只能10篇? #10
搜狗平台问题 #9
deal_article_comment(text=text)并不能获得用户的评论内容 #8
py2.7 什么时候支持? #7
PIL is not support Python3 #6
演示代码wechats.get_gzh_article_by_url_dict(wechat_info[‘url’])提示list index out of range #5
如何使用代理 #2
使用的是 python3 吗? #1
Merged pull requests:
* This Change Log was automatically generated by `github_changelog_generator <https://github.com/skywinder/Github-Changelog-Generator>`__
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
Details for the file wechatsogou-2.0.5.tar.gz.
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c997449ac5ba0d2582be0009ecdf68bf2f9447066a5593f398ed3955cbd682f
|
|
| MD5 |
74038a9ca5f747be6126a6afaf731e4c
|
|
| BLAKE2b-256 |
14342cdaaa2422580f1ecefb571696d1d890721c68bb00fb47346ce6229c06b1
|
Details for the file wechatsogou-2.0.5-py2.py3-none-any.whl.
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3db204772f91df3ab0e8aaadcb94b0f94b8bb74326a7110c09d7e3f85e8b5818
|
|
| MD5 |
6ecc5b7829f6d5e74029ec45279b23f4
|
|
| BLAKE2b-256 |
f5557e2d47d5430987664280830ae674f031be25c0a72fcedd02e8b146ef3c35
|