1 Star 0 Fork 0

codelong/wxspider

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
auto_add_mp.py 4.40 KB
一键复制 编辑 原始数据 按行查看 历史
# -*- coding: utf-8 -*-
#添加指定公众号到爬虫数据库
# 导入包
from wechatsogou.tools import *
from wechatsogou import *
from PIL import Image
import datetime
import time
import sys,locale
import logging
import logging.config
# 日志
logging.config.fileConfig('auto_add_mp_logging.conf')
logger = logging.getLogger()
# 搜索API实例
wechats = WechatSogouApi()
#数据库实例
mysql = mysql('add_mp_list')
#获取所有添加的微信公众号
add_list = mysql.find(0)
succ_count = 0
for add_item in add_list:
try:
print(add_item)
if add_item['wechatid']:
print("add by wechatid")
mysql.where_sql = "wechatid ='" + add_item['wechatid'] + "'"
mp_data = mysql.table('wechat_wechat').find(1)
if not mp_data :
wechat_info = wechats.get_gzh_info(add_item['wechatid'])
print wechat_info['url']
time.sleep(1)
print wechat_info['url']
print(wechat_info)
if(wechat_info != ""):
# mysql.table('mp_info').add({'name':wechat_info['name'],
# 'wx_hao':wechat_info['wechatid'],
# 'company':wechat_info['renzhen'],
# 'description':wechat_info['jieshao'],
# 'logo_url':wechat_info['img'],
# 'qr_url': wechat_info['qrcode'],
# 'wz_url': wechat_info['url'],
# 'last_qunfa_id': 0,
# 'create_time':time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))})
mysql.table('wechat_wechat').add({'name': wechat_info['name'],
'wechatid': wechat_info['wechatid'],
'intro': wechat_info['jieshao'],
'avatar': wechat_info['img'],
'qrcode': wechat_info['qrcode'],
'wz_url': wechat_info['url'],
'last_qunfa_id': 0,
'frequency': 1000,
'next_crawl_time': time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())),
'create_time': time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))})
else:
print(u"已经存在的公众号")
elif add_item['name']:
#获取对应信息
print("add by name")
wechat_infos = wechats.search_gzh_info(add_item['name'].encode('utf8'))
time.sleep(1)
#print(wechat_infos)
for wx_item in wechat_infos :
#公众号数据写入数据库
#搜索一下是否已经存在
print(wx_item['name'])
mysql.where_sql = "wechatid ='" + wx_item['wechatid'] + "'"
print(mysql.where_sql)
mp_data = mysql.table('mp_info').find(1)
if not mp_data :
print(wx_item['name'].decode("utf-8"))
mysql.table('wechat_wechat').add({'name': wx_item['name'],
'wechatid': wx_item['wechatid'],
# 'company':wx_item['renzhen'],
'intro': wx_item['jieshao'],
'avatar': wx_item['img'],
'qrcode': wx_item['qrcode'],
'wz_url': wx_item['url'],
'last_qunfa_id': 0,
'frequency': 1000,
'next_crawl_time': time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())),
'create_time': time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))})
else:
print(u"已经存在的公众号")
#删除已添加项
mysql.table('add_mp_list').where({'id': add_item['id']}).delete()
except Exception:
print(u"出错,继续")
continue
print("success")
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/studyLong/wxspider.git
git@gitee.com:studyLong/wxspider.git
studyLong
wxspider
wxspider
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385