下载站

展开
精品推荐
python词云图生成源码

python词云图生成源码

源码相关大小:619.77MB语言: / 类别:编程书集系统: / WinXP, Win7, win8 提供:
应用介绍

python词云图生成源码,用python来实现的一个词云图生成代码,可以生成某个论坛版块的词云图数据,使用python编译环境即可编译该程序,让你轻松获得想要的词云图数据。本次放出python词云图生成源码资源下载,感兴趣的朋友们不妨试试吧!

python词云生成代码说明:

由吾爱论坛大神制作

输入序号即可生成相关板块的词云信息

python词云图代码演示:

importrequests

fromlxmlimportetree

import?jieba

importnumpyasnp

importmatplotlib.pyplotasplt

importtime

fromPILimportImage

fromwordcloudimportWordCloud

defGetData(forumdata):

forjinforumdata:

url='https://www.52pojie.cn/forum-x-1'

url=url.split('-')

nurl=url+'-'+j+'-'+url+'.html'

html=requests.get(nurl)

ehtml=etree.HTML(html.text)

forumname=''.join(ehtml.xpath('//*[@id="ct-yunshe"]/div/div/div/h1/a/text()')).replace('『','').replace('』','')

print(forumname)

pagenum=ehtml.xpath('//*[@id="fd_page_top-yunshe"]/div/label/span/text()')

pagenum=pagenum.replace('/','').replace('页','')

txt=''

foriinrange(1,int(pagenum)+1):

nurl=url+'-'+j+'-'+str(i)+'.html'

html=requests.get(nurl)

ehtml=etree.HTML(html.text)

#pltxt=''.join(ehtml.xpath('//*[@id="threadlisttableid-yunshe"]/tbody/tr/td/cite/a/text()'))#获取帖子作者

pltxt=''.join(ehtml.xpath('//*[@class="sxst-yunshe"]/text()'))#帖子标题

txt=txt+pltxt

time.sleep(1)#给服务器留些喘气的时间

cut_text=txt

wordcloud=WordCloud(

font_path='simhei.ttf',

background_color='white',

width=800,

height=500

).generate(cut_text)

wordcloud.to_file('c:\\'+forumname+'.png')

plt.imshow(wordcloud,interpolation="bilinear")

plt.axis("off")

plt.show()

if__name__=='__main__':

forumdata=[

"2",?#原创发布区0

"5",?#脱壳破解区1

"65",?#移动安全区2

"59",?#软件调试区3

"24",?#编程语言区4

"6",?#动画发布区5

"4",?#逆向资源区6

"16",?#精品软件区7

"8",?#悬赏问答区8

"32",?#病毒分析区9

"50",?#病毒救援区10

"41"#安全工具区11

]

print('开始获取,请稍候...')

GetData(forumdata)

python词云图相关视频:

Tags:词云python,词云图,生成工具.

应用推荐查看更多
热门下载查看更多
精选应用
点击查看更多
专题合集查看更多
热门专题查看更多
友情链接0投诉联系:ichaoinc@gmail.com