词云制作

# -*- coding:utf-8 -*-
import matplotlib.pyplot as plt
from PIL import Image
from wordcloud import WordCloud , ImageColorGenerator
import numpy as np
import jieba
from imageio import imread

from urllib.request import urlopen
from urllib import request
from bs4 import BeautifulSoup
import socket
import time
from lxml import etree
import requests

def huitu():
    text = open(r'C:\Users\admin\Desktop\text.txt',"r",encoding="utf-8").read()

    cut_text=jieba.cut(text,cut_all=False)
    result='/'.join(cut_text)

    mask_of_result = imread(r'C:\Users\admin\Desktop\libai2.png')

    wc = WordCloud(font_path=r"C:\Users\admin\Desktop\msyhl.ttc",background_color="white", max_words=2000, mask=mask_of_result)

    wc.generate(result)

    wc.to_file(r'C:\Users\admin\Desktop\libaiciyun2.png')

    plt.imshow(wc, interpolation='bilinear')
    plt.axis("off")
    plt.figure()
    plt.imshow(mask_of_result, cmap=plt.cm.gray, interpolation='bilinear')
    plt.axis("off")
    plt.show()



def find_libaisici(url_num=1):
    url = "http://www.shicimingju.com/chaxun/zuozhe/1_"+str(url_num)+".html"

    with requests.request('GET', url) as res:
        content = res.text  # 获取HTML的内容
        html = etree.HTML(content)  # 分析HTML,返回DOM根节点
        orders = html.xpath('//*[@class="shici_content"]/text()')
        print(orders)

if __name__ == "__main__":
    # for i in range(1,50):
    #     find_libaisici(i)

    huitu()



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值