Pythonpython 案例itchat 查看手机微信中用户比例 import itchat import pandas as pd # Python抓取微信好友数量、性别、城市分布,以及将py文件打包成exe. #https://zhuanlan.zhihu.com/p/73295760 # 先登录 itchat.auto_login(hotReload=True) # 获取好友列表作者王明昌发布时间2019-10-05最后更新2019-10-05文章目录itchat 查看手机微信中用户比例获取文章中的美女图词云itchat 查看手机微信中用户比例复制import itchat import pandas as pd # Python抓取微信好友数量、性别、城市分布,以及将py文件打包成exe. #https://zhuanlan.zhihu.com/p/73295760 # 先登录 itchat.auto_login(hotReload=True) # 获取好友列表 friends = itchat.get_friends(update=True)[0:] #number_friends = itchat.get_friends(update=True) number_of_friends = len(friends) # 初始化计数器,有男有女,当然,有些人是不填的 male = female = other = 0 # 遍历这个列表,列表里第一位是自己,所以从"自己"之后开始计算 # 1表示男性,2女性 for i in friends[1:]: sex = i["Sex"] if sex == 1: male += 1 elif sex == 2: female += 1 else: other += 1 # 总数算上,好计算比例啊~ total = len(friends[1:]) #好友城市分布 df_friends = pd.DataFrame(friends) City = df_friends.City City_count = City.value_counts() City_count = City_count[City_count.index != ''] # 好了,打印结果 friends_numbers = str(number_of_friends) man = (u"男性好友:%.2f%%" % (float(male) / total * 100)) women = (u"女性好友:%.2f%%" % (float(female) / total * 100)) others = (u"其他:%.2f%%" % (float(other) / total * 100)) city = City_count with open('wechat.txt', 'w') as f: f.write(friends_numbers) f.write('\n'+man) f.write(women) f.write('\n'+str(city))  获取文章中的美女图复制# _*_coding:utf-8_*_ from urllib.parse import urljoin import requests import re import os class GetImage(object): def __init__(self, url): self.url = url self.headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36' } self.dir_path = os.path.dirname(os.path.abspath(__file__)) self.path = self.dir_path + '/imgs' isExists = os.path.exists(self.dir_path + '/imgs') # 创建目录 if not isExists: os.makedirs(self.path) def download(self, url): try: res = requests.get(url, headers=self.headers) return res except Exception as E: print(url + '下载失败,原因:' + E) def parse(self, res): content = res.content.decode() # print(content) img_list = re.findall(r'词云 复制# 导入扩展库 import re # 正则表达式库 import collections # 词频统计库 import numpy as np # numpy数据处理库 import jieba # 结巴分词 import wordcloud # 词云展示库 from PIL import Image # 图像处理库 import matplotlib.pyplot as plt # 图像展示库 # 读取文件 fn = open('article.txt') # 打开文件 string_data = fn.read() # 读出整个文件 fn.close() # 关闭文件 # 文本预处理 pattern = re.compile(u'\t|\n|\.|-|:|;|\)|\(|\?|"') # 定义正则表达式匹配模式 string_data = re.sub(pattern, '', string_data) # 将符合模式的字符去除 # 文本分词 seg_list_exact = jieba.cut(string_data, cut_all = False) # 精确模式分词 object_list = [] remove_words = [u'的', u',',u'和', u'是', u'随着', u'对于', u'对',u'等',u'能',u'都',u'。',u' ',u'、',u'中',u'在',u'了', u'通常',u'如果',u'我们',u'需要'] # 自定义去除词库 for word in seg_list_exact: # 循环读出每个分词 if word not in remove_words: # 如果不在去除词库中 object_list.append(word) # 分词追加到列表 # 词频统计 word_counts = collections.Counter(object_list) # 对分词做词频统计 word_counts_top10 = word_counts.most_common(10) # 获取前10最高频的词 print (word_counts_top10) # 输出检查 # 词频展示 mask = np.array(Image.open('img/love.jpg')) # 定义词频背景 wc = wordcloud.WordCloud( font_path="./font/simhei.ttf",# 设置字体格式 mask=mask, # 设置背景图 max_words=200, # 最多显示词数 max_font_size=100 # 字体最大值 ) wc.generate_from_frequencies(word_counts) # 从字典生成词云 image_colors = wordcloud.ImageColorGenerator(mask) # 从背景图建立颜色方案 wc.recolor(color_func=image_colors) # 将词云颜色设置为背景图方案 plt.imshow(wc) # 显示词云 plt.axis('off') # 关闭坐标轴 plt.show() # 显示图像 ###
2018-01-052017传智播客黑马Python就业+基础班视频教程好像python挺火的,最近学计算机的同学也建议我接触学习一下,某宝买的教程分享出来,大家各取所需。 基础班和软件:https://pan.baidu.com/s/1hr6zAbM 密码:[reply
2019-10-05python request模块sign token获取不到可测试手机端 百度翻译(案例) import requests header = { 'user-agent': 'Mozilla/5.0 (Linux; Android
2019-10-05python连接mysql数据库安装 安装 pip3 install pymysql python3 import pymysql python2 import MySQLdb 操作sql 增 import pymysql conn
2019-10-05python 通用爬虫(百度贴吧)import requests class TiebaSpider(): def __init__(self,tieba_name): self.tieba_name = tieba_name pri
2018-12-25Python | 从零学习pythonmac下载/安装环境 https://www.python.org/downloads/release/python-372/ 测试是否安装(命令行) python3 //mac自带python2 出
2020-07-29python 采集唯美girlimport requests; import re; import os; # 1.请求网页 header = { "user-agent":'Mozilla/5.0 (Macintosh; Int