代码拉取完成,页面将自动刷新
# -*- 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")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。