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

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

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

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

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

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

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

    import requests
    from bs4 import BeautifulSoup
    
    # 获取新闻细节
    def getNewsDetail(newsUrl):
        resd = requests.get(newsUrl)
        resd.encoding = 'utf-8'
        soupd = BeautifulSoup(resd.text, 'html.parser')
        content = soupd.select('.cont')[0].text.rsplit("青云志下载地址:http://www.80smp4.net/mp4_3gp/30833/")[0]
        print('内容:{}'.format(content))
    
    # 获取列表页新闻
    def getListPage(listUrl):
        res = requests.get(listUrl)
        res.encoding = 'utf-8'
        soup = BeautifulSoup(res.text, 'html.parser')
    
        for new in soup.select('div'):
            if len(new.select('.ph_u')) > 0:
                description = new.select('.title')[0].text.split()[0]
                newsUrl = new.select('a')[2]['href']
                # print('标题:{0}
    内容:{1}
    链接:{2}'.format(title, description, newsUrl))
                # 调用getNewsDetail()获取新闻详情
                print('片名:{0}
    连接:{1}'.format(description,newsUrl))
                getNewsDetail(newsUrl)
                break
    
    firstUrl = 'http://www.80smp4.net/tv/'
    getListPage(firstUrl)

    效果图如下:

    运用http://www.picdata.cn/index.php词云生成器进行词云分析并生成词云图:

  • 相关阅读:
    2018QBXT刷题游记(4)
    洛谷 P4302 字符串折叠 题解
    hdu5009 Paint Pearls 题解
    CF467C George and Job 题解
    洛谷P2622 关灯问题II 题解
    洛谷 P3049园林绿化 题解
    洛谷 P1064 金明的预算方案 题解
    洛谷P1979 华容道 题解
    2018QBXT刷题游记(3)
    2018QBXT刷题游记(2)
  • 原文地址:https://www.cnblogs.com/hhmk/p/8974897.html
Copyright © 2011-2022 走看看