zoukankan      html  css  js  c++  java
  • 爬虫大作业

    1.选一个自己感兴趣的主题或网站。(所有同学不能雷同)

    2.用python 编写爬虫程序,从网络上爬取相关主题的数据。

    3.对爬了的数据进行文本分析,生成词云。

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

    5.写一篇完整的博客,描述上述实现过程、遇到的问题及解决办法、数据分析思想及结论。

    6.最后提交爬取的全部数据、爬虫及数据分析源代码。

    import requests
    from bs4 import BeautifulSoup
    import jieba.analyse
    from PIL import Image
    import numpy as np
    import matplotlib.pyplot as plt
    from wordcloud import WordCloud,ImageColorGenerator
    
    
    url = "https://item.btime.com/36soaocmq3b884qcrm1phg2upnh?from=haozcxw"
    res = requests.get(url)
    res.encoding = 'utf-8'
    soup = BeautifulSoup(res.text,'html.parser')
    
    
    title = soup.select('.title')[0].text
    content = soup.select('.content-text')[0].text
    
    f = open('conten.txt', 'a', encoding='utf-8')
    f.write(content)
    f.close()
    
    strl = ''',。、‘’ '''
    for i in strl:
        ls = content.replace(i," ")
        print(ls)
    
    
    lyric= ''
    f=open('conten.txt','r', encoding='utf-8')
    for i in f:
        lyric+=f.read()
    
    
    result=jieba.analyse.textrank(lyric,topK=50,withWeight=True)
    keywords = dict()
    for i in result:
        keywords[i[0]]=i[1]
    print(keywords)
    
    image= Image.open('11c1e099855d27b7cf3e174e25e501cc_t015f10572a0691eaa8.jpg')
    graph = np.array(image)
    wc = WordCloud(font_path='./fonts/simhei.ttf',background_color='White',max_words=50,mask=graph)
    wc.generate_from_frequencies(keywords)
    image_color = ImageColorGenerator(graph)
    plt.imshow(wc)
    plt.imshow(wc.recolor(color_func=image_color))
    plt.axis("off")
    plt.show()
    wc.to_file('d.jpg')

  • 相关阅读:
    makefile中的wildcard和patsubst
    makefile中=,:=,?=,+=区别
    hash函数查找和ASL计算
    ubuntu apt-get提示no dependencys怎么办
    增广贤文是不多的古典珍宝之一
    如何打印查看c++stack<..>中的内容(不使用pop,top)
    c/c++标准IO重定向
    c/c++使用#define,#ifdef,#endif将debug代码分离
    未完待续
    c++重载覆盖重定义多态其他别名区别
  • 原文地址:https://www.cnblogs.com/ming-z/p/8933220.html
Copyright © 2011-2022 走看看