python微信api_用Python实现微信公众号API素材库图文消息抓取
[Python] 纯文本查看 复制代码# -*- coding:utf-8 -*-
import os
import urllib.parse
from html.parser import HTMLParser
import requests
from bs4 import BeautifulSoup
from pymongo import MongoClient
class ContentHtmlParser(HTMLParser):
"""
过滤html标签
"""
def __init__(self):
HTMLParser.__init__(self)
self.text = ""
def handle_data(self, data):
self.text += data
def get_text(self):
return self.text
mongo_client = MongoClient("ip", 27017)
mongo_db = mongo_client["gongzhonghao"]
def get_words():
words = []
with open("words.txt", encoding="utf-8") as words_file:
for lines in words_file.readlines():
if len(lines.strip()) == 0:
continue
if lines.find("、") != -1:
for p in lines.split("、"):
words.append(p.replace("\n", ""))
else:
words.append(lines.replace("\n", ""))
return words
def get_articles(clt):
articles = []
collection = mongo_db[clt]
doc = collection.find_one()
items = doc["items"]
for it in items:
content = it["content"]["news_item"][0]
articles.append(content)
return articles
def download(dir, file_name, url):
if not os.path.exists(dir):
os.mkdir(dir)
try:
resp = requests.get(url)
path = dir + "\\" + file_name
if os.path.exists(path):
return
with open(path, "wb") as f:
f.write(resp.content)
except :
print(url)
def find_images(content):
imgs = []
c = urllib.parse.unquote(content)
img_labels = BeautifulSoup(c, "html.parser").find_all("img")
for img in img_labels:
src = img.get("data-src")
imgs.append(src)
return imgs
def get_suffix(url):
try:
suffix = url[url.rindex("=") + 1:]
if suffix == "jpeg" or suffix == "other":
return ".jpg"
return "." + suffix
except:
return ".jpg"
def filter_content(content):
parser = ContentHtmlParser()
parser.feed(content)
return parser.get_text()
def check_jinyongci(content):
fc = filter_content(content)
words = get_words()
invalids = []
for w in words:
if fc.find(w) != -1:
invalids.append(w)
return invalids
def save_jinyongci(clt, title, invalids):
if len(invalids) == 0:
return
file = clt + "\\invalid.txt"
with open(file, "a+",encoding="utf-8") as f:
f.write("标题:" + title)
f.write("\r\n敏感词:")
for iv in invalids:
f.write(iv)
f.write("、")
f.write("\r\n\r\n")
if __name__ == "__main__":
clt = "xxx"
if not os.path.exists(clt):
os.mkdir(clt)
articles = get_articles(clt)
print(clt + ": 共" + str(len(articles)) + "个")
for i in range(0, len(articles)):
print("正在处理第 " + str(i) + " 个")
title = articles[i]["title"]
thumb_url = articles[i]["thumb_url"]
content = articles[i]["content"]
# 下载封面
# path = os.path.join(clt, title)
fname = str(i) + "_" + title.replace("|", "").replace("<", "").replace(">", "")
download(clt, fname + get_suffix(thumb_url), thumb_url)
# 找出文章中的图片
imgs = find_images(content)
index = 0
for img in imgs:
download(clt, fname + "_" + str(index) + get_suffix(img), img)
index = index + 1
# 找出文章中的敏感词
invalids = check_jinyongci(content)
print(invalids,'----',title)
save_jinyongci(clt, title, invalids)
python微信api_用Python实现微信公众号API素材库图文消息抓取相关推荐
- python pc微信 接收信息_GitHub - ericadver/WechatPCAPI: 微信PC版的API接口,可通过Python调用微信获取好友、群、公众号列表,并收发消息等功能。...
WechatPCAPI 微信PC版的API接口,可通过Python调用微信获取好友.群.公众号列表,并收发消息等功能.可用于二次开发在线微信机器人.微信消息监控.群控软件.开发界面作多个微信控制软件等 ...
- python 微信公众号网页接口调用_GitHub - micsem00/WechatPCAPI: 微信PC版的API接口,可通过Python调用微信获取好友、群、公众号列表,并收发消息等功能。...
WechatPCAPI 微信PC版的API接口,可通过Python调用微信获取好友.群.公众号列表,并收发消息等功能.可用于二次开发在线微信机器人.微信消息监控.群控软件.开发界面作多个微信控制软件等 ...
- python的读取微信界面_GitHub - lchb000/WechatPCAPI: 微信PC版的API接口,可通过Python调用微信获取好友、群、公众号列表,并收发消息等功能。...
WechatPCAPI 微信PC版的API接口,可通过Python调用微信获取好友.群.公众号列表,并收发消息,接受转账.好友请求.入群请求,群管理等功能.可用于二次开发在线微信机器人.微信消息监控. ...
- python 接收微信pc端_GitHub - linhuisheng/WechatPCAPI: 微信PC版的API接口,可通过Python调用微信获取好友、群、公众号列表,并收发消息等功能。...
WechatPCAPI 微信PC版的API接口,可通过Python调用微信获取好友.群.公众号列表,并收发消息等功能.可用于二次开发在线微信机器人.微信消息监控.群控软件.开发界面作多个微信控制软件等 ...
- php 公众号多图文消息,微信公众号怎样制作多图文消息?
原标题:微信公众号怎样制作多图文消息? 废话不多说,先上一波图: 怎样可以把多篇文章同时发送? 当然,这个为题对于我们运营老司机来说不叫事儿,但是会者不难,难者不会,有很多新手小白就是不知道怎样可以群 ...
- java上传图文消息_微信公众号开发之上传图文消息素材(十二)
群发消息太重要了,公众号管理员需要定期通过公众号群发一些消息,用户通过推送的消息可以定期了解公众号的最新信息. 群发图文消息的过程如下: 首先,预先将图文消息中需要用到的图片,使用上传图文消息内图片接 ...
- java向微信公众号---发送模板和图文消息
微信公众号初次开发 其他操作 项目搭建 maven application.yml yml参数配置 微信客户端配置 搭建完成 实现业务 模板消息推送 准备工作 模板消息填写要求 图文消息填写要求 推送 ...
- 微信公众号推送多图文消息,直接跳转至外部链接(wxJava)
文章目录 前言 一.解决思路 1.公众号后台设置 2.客服消息 3.google & baidu 寻找答案 4.关注后自动推送(正解) 总结 前言 需求:用户关注公众号后,如何在微信推送的多图 ...
- python爬取公众号历史文章_pythons爬虫:抓取微信公众号 历史文章(selenium+phantomjs)...
原标题:pythons爬虫:抓取微信公众号 历史文章(selenium+phantomjs) 大数据挖掘DT数据分析 公众号: datadw 本文爬虫代码可以通过回复本公众号关键字"公众号& ...
最新文章
- 【杠精】问卷星防切屏解除方法-解除问卷星平台模拟考试防作弊切屏和最大化全屏的方法
- matlab怎么根据波宽度去波,使用Matlab图像处理(三)——图像滤波原理
- python画玫瑰花的代码_python绘制玫瑰的实现代码
- Ubuntu 下Ape转Mp3[88250原创]
- TensorFlow ImportError: (‘Failed to import pydot. You must `pip install pydot`)
- 63个优秀测试网站地址【个人总结】
- php 导出csv文件
- 面试官:为什么 Spring Boot 的 jar 可以直接运行
- python 内推_[宜配屋]听图阁
- 05-不是内部或外部命令,也不是可运行的程序或批处理文件
- kubernetes 应用快速入门
- 便利店小程序需要服务器吗,便利店开发小程序的功能
- Linux下读写UART串口的代码
- 纷杂的Spring-boot-starter: 3 数据访问与spring-boot-starter-jdbc
- GJB 5000A与GJB 5000B区别
- 下载安装electron和electron-builder遇到的问题及部分解决办法
- 二十一世纪大学英语读写教程(第三册)学习笔记(原文)——5 - America Seen with European Eyes(概说美国——欧洲人眼中的美国)
- 玩传奇的伙计们,很久没发朋友圈了吧,今天给大家找到一些朋友圈高逼格文案。
- Scratch少儿趣味编程pdf
- [UER #1] DZY Loves Graph
热门文章
- Matlab实现Holland风场
- 华为手机nova计算机怎么找过程,华为nova手机拆机全过程 华为nova真机拆解图解教程...
- FBX 解析 材质与贴图
- Android报错installation failed with message invalid file E://.....
- UNI-APP,uni.scanCode扫码页面显示英文,uni.showActionSheet自带取消按钮显示英文问题的解决
- android studio开发微信界面
- Altium Designer 2020 学习笔记(一)-----原理图及原理图库部分(配动态图操作演示)
- -XX:+DisableExplicitGC弊端
- 手把手教你设计短信验证码
- TypeError Cannot instantiate abstract class xxx with abstract method