コード例 #1
0
def print_others(msg):
    '''1、先判断消息是Sharing类型,获取URL并对文本进行统计,输出前100的词频'''
    if msg.type == 'Sharing':  #如果是sharing类型
        response = requests.get(msg.url)  #msg.url为分享的网址
        document = PyQuery(response.text)
        content = document('#js_content').text()
        #结巴处理
        result = stats_word.stast_text_cn(content, count=10)
        result_dict = dict(result)
        word = []
        number = []
        for i in result_dict:
            word.append(i)
            number.append(result_dict[i])
        plt.rcdefaults()
        fig, ax = plt.subplots()
        y = np.arange(len(word))
        error = np.random.rand(len(word))
        plt.rcParams['font.sans-serif'] = ['SimHei']  # 将中文字体显现
        ax.barh(y, number, xerr=error, align='center', color='red')
        ax.set_yticks(y)
        ax.set_yticklabels(word)
        ax.invert_yaxis()
        ax.set_xlabel('出现次数')
        ax.set_title('词频统计表')
        plt.savefig('day13.png')
        msg.reply_image('day13.png')
コード例 #2
0
def print_others(msg):
    '''1、先判断消息是Sharing类型,获取URL并对文本进行统计,输出前100的词频'''
    if msg.type == 'Sharing':  #如果是sharing类型
        response = requests.get(msg.url)  #msg.url为分享的网址
        document = PyQuery(response.text)
        content = document('#js_content').text()
        #结巴处理
        result = stats_word.stast_text_cn(content, count=100)
        msg.reply(result)  #发送result的内容给好友
コード例 #3
0
import stats_word

with open(
        'f:/zixuepython/selfteaching-python-camp/exercises/1901050060/d10/mymodule/tang300.json',
        'r',
        encoding='UTF-8') as f:
    text = f.read()
f.close()

try:
    print(stats_word.stast_text_cn(text, 20))
except ValueError as w:
    print(w)
コード例 #4
0
import yagmail
import requests
from pyquery import PyQuery as py
import stats_word as sw
import getpass

r = requests.get("https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA")  #获取网页的数据
web_text = r.text
document = py(web_text)
content = document('#js_content').text()
#print(content)

result = sw.stast_text_cn(content, 100)
result = str(result)

sender = input("请输入发件人的邮箱:")
password = getpass.getpass("请输入发件人邮箱的密码:")

yagmail.register(sender, password)
yag = yagmail.SMTP(sender, password, 'smtp.qq.com')
yag.send('*****@*****.**', '1901050059 jeasonlj525', result)
print("发送成功")
コード例 #5
0
import stats_word
import requests
from pyquery import PyQuery
import getpass
import yagmail

response=requests.get('https://mp.weixin.qq.com/s/pLmuGoc4bZrMNl7MSoWgiA')
document=PyQuery(response.text)
content=document('#js_content').text()
result= stats_word.stast_text_cn(content,100)
result_str = ''.join(str(i) for i in result)
print('结果为:',result_str)

sender=input('输入发件人邮箱:')
password=getpass.getpass('输入发件人邮箱密码:')
recipients='*****@*****.**'
files=result_str
yagmail.SMTP(sender,password).send(recipients,'自学训练营学习7群DAY11 ooocooc',result_str)
yag=yagmail.SMTP(sender,password,host='smtp.qq.com')
yag.send(recipients,'自学训练营学习7群DAY11 ooocooc',files)