当前位置:   article > 正文

python程序设计期末大作业,python期末大作业300行_python300行代码大作业

python300行代码大作业

本篇文章给大家谈谈python程序设计期末大作业,以及python期末大作业300行,希望对各位有所帮助,不要忘了收藏本站喔。

 

importrequestsimportrefrom bs4 importBeautifulSoupfrom datetime importdatetimeimportpandasimportsqlite3importjiebafrom wordcloud importWordCloudimportmatplotlib.pyplot as plt

url= "http://www.xinhuanet.com/"f=open("css.txt","w+")

res0=requests.get(url)

res0.encoding="utf-8"soup= BeautifulSoup(res0.text,"html.parser")

newsgroup=[]for news in soup.select("li"):if len(news.select("a"))>0:print(news.select("a")[0].text)

title=news.select("a")[0].text

f.write(title)

f.close()

f0= open('css.txt','r')

qz=[]

qz=f0.read()

f0.close()print(qz)

words=list(jieba.cut(qz))

ul={':','的','"','、','”','“','PHP与PYTHON:基于语法,功能,应用程序等的详细比较。','!',':','?',' ','\u3000',',','\n'}

dic={}

keys= set(words)-ulfor i inkeys:

dic[i]=words.count(i)

c=list(dic.items())

c.sort(key=lambda x:x[1],reverse=True)

f1= open('diectory.txt','w')for i in range(10):print(c[i])for words_count in range(c[i][1]):

f1.write(c[i][0]+' ')

f1.close()

df=pandas.DataFrame(words)print(df.head())

with sqlite3.connect('newsdb3.sqlite') as db:

df.to_sql('newsdb3',con =db)

f3= open('diectory.txt','r')

cy_file=f3.read()

f3.close()

cy=WordCloud().generate(cy_file)

plt.imshow(cy)

plt.axis("off")

plt.show()

文章知识点与官方知识档案匹配,可进一步学习相关知识
Python入门技能树首页概览405476 人正在系统学习中
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/318922
推荐阅读
相关标签
  

闽ICP备14008679号