基于搜狗微信搜索的微信公众号爬虫接口
===
[](https://github.com/Chyroc/WechatSogou)
[](https://github.com/Chyroc/WechatSogou)
[](https://github.com/Chyroc/WechatSogou)
[](https://github.com/Chyroc/WechatSogou)
[](https://github.com/Chyroc/WechatSogou)
我的另外一个作品: https://github.com/chyroc/lark ,基于代码生成的 Lark/飞书 Go SDK,欢迎 star 。

```
__ __ _ _ ____
\ \ / /__ ___| |__ __ _| |_/ ___| ___ __ _ ___ _ _
\ \ /\ / / _ \/ __| '_ \ / _` | __\___ \ / _ \ / _` |/ _ \| | | |
\ V V / __/ (__| | | | (_| | |_ ___) | (_) | (_| | (_) | |_| |
\_/\_/ \___|\___|_| |_|\__,_|\__|____/ \___/ \__, |\___/ \__,_|
|___/
```
# 项目简介
基于搜狗微信搜索的微信公众号爬虫接口,可以扩展成基于搜狗搜索的爬虫
如果有问题,请提issue
[CHANGELOG](./CHANGELOG.md)
# 交流分享
- QQ群(只需加一个)
- 一群 132955136(已满)
- 二群 819084985
- 微信群
# 赞助作者
甲鱼说,咖啡是灵魂的饮料,买点咖啡
[谢谢这些人的☕️](./coffee.md)
支付宝扫码大家一起领红包:
<img src="https://raw.githubusercontent.com/chyroc/wechatsogou/master/screenshot/alipay_hongbao.png" width="250" />
或者直接转账:
<img src="https://raw.githubusercontent.com/chyroc/wechatsogou/master/screenshot/pay_wechat.jpg" width="250" /><img src="https://raw.githubusercontent.com/chyroc/wechatsogou/master/screenshot/pay_ali.jpg" width="250" />
# 问题集锦
Q:没有得到原始文章url / 提示链接已经过期?
A:微信屏蔽此接口,请在临时链接有效期内保存文章内容。
Q:获取文章只能10篇?
A:是的,仅显示最近10条群发。
Q:使用的是python 2 还是 3?
A:都支持,若出错,请报BUG。
# 安装
```
pip install wechatsogou --upgrade
```
# 使用
### 初始化 API
```python
import wechatsogou
# 可配置参数
# 直连
ws_api = wechatsogou.WechatSogouAPI()
# 验证码输入错误的重试次数,默认为1
ws_api = wechatsogou.WechatSogouAPI(captcha_break_time=3)
# 所有requests库的参数都能在这用
# 如 配置代理,代理列表中至少需包含1个 HTTPS 协议的代理, 并确保代理可用
ws_api = wechatsogou.WechatSogouAPI(proxies={
"http": "127.0.0.1:8888",
"https": "127.0.0.1:8888",
})
# 如 设置超时
ws_api = wechatsogou.WechatSogouAPI(timeout=0.1)
```
### 获取特定公众号信息 - get_gzh_info

- 使用
```
In [5]: import wechatsogou
...:
...: ws_api =wechatsogou.WechatSogouAPI()
...: ws_api.get_gzh_info('南航青年志愿者')
...:
Out[5]:
{
'authentication': '南京航空航天大学',
'headimage': 'http://img01.sogoucdn.com/app/a/100520090/oIWsFt1tmWoG6vO6BcsS7St61bRE',
'introduction': '南航大志愿活动的领跑者,为你提供校内外的志愿资源和精彩消息.',
'post_perm': 26,
'view_perm': 1000,
'profile_url': 'http://mp.weixin.qq.com/profile?src=3×tamp=1501140102&ver=1&signature=OpcTZp20TUdKHjSqWh7m73RWBIzwYwINpib2ZktBkLG8NyHamTvK2jtzl7mf-VdpE246zXAq18GNm*S*bq4klw==',
'qrcode': 'http://mp.weixin.qq.com/rr?src=3×tamp=1501140102&ver=1&signature=-DnFampQflbiOadckRJaTaDRzGSNfisIfECELSo-lN-GeEOH8-XTtM*ASdavl0xuavw-bmAEQXOa1T39*EIsjzxz30LjyBNkjmgbT6bGnZM=',
'wechat_id': 'nanhangqinggong',
'wechat_name': '南航青年志愿者'
}
```
- 返回数据结构
```python
{
'profile_url': '', # 最近10条群发页链接
'headimage': '', # 头像
'wechat_name': '', # 名称
'wechat_id': '', # 微信id
'post_perm': int, # 最近一月群发数
'view_perm': int, # 最近一月阅读量
'qrcode': '', # 二维码
'introduction': '', # 简介
'authentication': '' # 认证
}
```
### 搜索公众号

- 使用
```
In [6]: import wechatsogou
...:
...: ws_api =wechatsogou.WechatSogouAPI()
...: ws_api.search_gzh('南京航空航天大学')
...:
Out[6]:
[
{
'authentication': '南京航空航天大学',
'headimage': 'http://img01.sogoucdn.com/app/a/100520090/oIWsFt1MvjqspMDVvZjpmxyo36sU',
'introduction': '南京航空航天大学官方微信',
'post_perm': 0,
'view_perm': 0,
'profile_url': 'http://mp.weixin.qq.com/profile?src=3×tamp=1501141990&ver=1&signature=S-7U131D3eQERC8yJGVAg2edySXn*qGVi5uE8QyQU034di*2mS6vGJVnQBRB0It9t9M-Qn7ynvjRKZNQrjBMEg==',
'qrcode': 'http://mp.weixin.qq.com/rr?src=3×tamp=1501141990&ver=1&signature=Tlp-r0AaBRxtx3TuuyjdxmjiR4aEJY-hjh0kmtV6byVu3QIQYiMlJttJgGu0hwtZMZCCntdfaP5jD4JXipTwoGecAze8ycEF5KYZqtLSsNE=',
'wechat_id': 'NUAA_1952',
'wechat_name': '南京航空航天大学'
},
{
'authentication': '南京航空航天大学',
'headimage': 'http://img01.sogoucdn.com/app/a/100520090/oIWsFtwVmjdK_57vIKeMceGXF5BQ',
'introduction': '南京航空航天大学团委官方微信平台',
'post_perm': 0,
'view_perm': 0,
'profile_url': 'http://mp.weixin.qq.com/profile?src=3×tamp=1501141990&ver=1&signature=aXFQrSDOiZJHedlL7vtAkvFMckxBmubE9VGrVczTwS601bOIT5Nrr8Pcgs6bQ-oEd6jdQ0aK5WCQjNwMAhJnyQ==',
'qrcode': 'http://mp.weixin.qq.com/rr?src=3×tamp=1501141990&ver=1&signature=7Cpbd9CVQsXJkExRcU5VM6NuyoxDQQfVfF7*CGI-PTR0y6stHPtdSDqzAzvPMWz67Xz9IMF2TDfu4Cndj5bKxlsFh6wGhiLH0b9ZKqgCW5k=',
'wechat_id': 'nuaa_tw',
'wechat_name': '南京航空航天大学团委'
},
...
]
```
- 数据结构
list of dict, dict:
```python
{
'profile_url': '', # 最近10条群发页链接
'headimage': '', # 头像
'wechat_name': '', # 名称
'wechat_id': '', # 微信id
'post_perm': int, # 最近一月群发数
'view_perm': int, # 最近一月阅读量
'qrcode': '', # 二维码
'introduction': '', # 介绍
'authentication': '' # 认证
}
```
### 搜索微信文章

- 使用
```
In [7]: import wechatsogou
...:
...: ws_api =wechatsogou.WechatSogouAPI()
...: ws_api.search_article('南京航空航天大学')
...:
Out[7]:
[
{
'article': {
'abstract': '【院校省份】江苏【报名时间】4月5日截止【考试时间】6月10日-11日南京航空航天大学2017年自主招生简章南京航空航天大学2017...',
'imgs': ['http://img01.sogoucdn.com/net/a/04/link?appid=100520033&url=http://mmbiz.qpic.cn/mmbiz_png/P07yicBRJfC71QB3lREx4J4x34QOibGaia5BkiaaiaiaibicWkTBULou9R08K6FaxlUA1RFBFWCmpO1Lepk7ZcXK45vguQ/0?wx_fmt=png'],
'time': 1490270644,
'title': '南京航空航天大学2017年自主招生简章',
'url': 'http://mp.weixin.qq.com/s?src=3×tamp=1501142580&ver=1&signature=hRMlQOLQpu4BNhBACavusZdmk**D65qHyz5LWDq1lPjVcm7*iiBS0l7Pq40h0fiCX*bZ8vSMLzAMDNzELYFKIQ7mND0-7cQi-N0BtfTBql*CQdsHun-GtaYEqRva6Ukwce3gZh46SXJzo90kyZ3dwVYl6*589bGDIzG6JTGfpxI='
},
'gzh': {
'headimage': 'http://wx.qlogo.cn/mmhead/Q3auHgzwzM5kiawibor6ABhnibMYnOADvqdcrl5XWiaFfM5mGYZ8cUica6A/0',
'isv': 0,
'profile_url': 'http://mp.weixin.qq.com/profile?src=3×tamp=1501142580&ver=1&signature=dVkDdcFr1suL1WHdCOJj7pwZhG9W*