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词云生成器进行词云分析并生成词云图:

  • 相关阅读:
    转 哪个家伙说“网站去.Net化”?
    javascript prototype
    Spring作用,MVC容器作用
    javascript 闭包
    导入Excel数据至Access 宁静以致远
    My first mobile message 宁静以致远
    MyEclipse遇到的错误
    JAVAEE错误处理
    JavaEE ActionForm的高级应用
    hibernate
  • 原文地址:https://www.cnblogs.com/hhmk/p/8974897.html
Copyright © 2011-2022 走看看