一个完整的大作业

1.选一个自己感兴趣的主题。

本次选取主题为PC游戏及相关游戏新闻,网址为”http://www.gamersky.com/“

代码

import requests

import jieba
from bs4 import BeautifulSoup
from wordcloud import WordCloud
import re
import sys


url='http://www.gamersky.com/'
res = requests.get(url)
res.encoding='utf-8'
soup = BeautifulSoup(res.text,'html.parser')

 
for news in soup.select('li'):
    if len(news.select('a'))>0:
        title=news.select('a')[0].text
        url=news.select('a')[0]['href']
        fo = open('ciku.txt', "ab+")
        fo.write((title + '\r\n').encode('UTF-8'))
        fo.close()
        print(title,url)
txt = open('ciku.txt',"r",encoding='utf-8').read()
ex = {}
 
ls = []
words = jieba.lcut(txt)
counts = {}
for word in words:
    ls.append(word)
    if len(word) == 1:
        continue
    else:
        counts[word] = counts.get(word,0)+1
for word in ex:
    del(counts[word])
     
items = list(counts.items())
items.sort(key = lambda x:x[1], reverse = True)
for i in range(20):
    word , count = items[i]
    print ("{:<10}{:>5}".format(word,count))
 
mywc = WordCloud().generate(word)
    plt.imshow(mywc)
    plt.axis("off")
    plt.show()

 

2.网络上爬取相关的数据。

 

 

3.进行文本分析,生成词云。

 

4.对文本分析结果解释说明。

从分析结果来看,作为游戏的热点,刺客信条,绝地求生分别占有了单机游戏与联网游戏的头条位置,有相当大的热度,除此之外正在进行S7世界赛的游戏英雄联盟中的一些装备也正被热切讨论,这也同样是一个关注点。

5.写一篇完整的博客,附上源代码、数据爬取及分析结果,形成一个可展示的成果。

 

posted @ 2017-10-31 15:09  少钏_leo  阅读(236)  评论(0编辑  收藏  举报