获取全部校园新闻(GZCC大新闻流量刷新器)

import requests
import re

url = "http://news.gzcc.cn/html/xiaoyuanxinwen/"
listnewurl = "http://news.gzcc.cn/html/xiaoyuanxinwen/index.html"

res = requests.get(url)
reslist = requests.get(listnewurl)

res.encoding = ‘utf-8‘

# 利用BeautifulSoup的HTML解析器,生成结构树
from bs4 import BeautifulSoup

soup = BeautifulSoup(res.text, ‘html.parser‘)
soup_list = BeautifulSoup(reslist.text, ‘html.parser‘)

def getlistnew(listnewurl):  # 获取简单的新闻
    reslist = requests.get(listnewurl)
    reslist.encoding = ‘utf-8‘

    soup_list = BeautifulSoup(reslist.text, ‘html.parser‘)

    tou = ‘http://news.gzcc.cn/html/xiaoyuanxinwen/‘
    shuzi = ‘‘
    wei = ‘.html‘

    for news in soup_list.select(‘li‘):  #首页
        if len(news.select(‘.news-list-title‘)) > 0:
            # 首页文章标题
            title = news.select(‘.news-list-title‘)[0].text
            # 首页文章链接
            href = news.select(‘a‘)[0][‘href‘]

            print(‘------------------------------------------------------------------------------‘)
            print("文章标题:" + title)
            print("\n文章链接:" + href)

    for i in range(2, 233):  #首页外全部
        shuzi = i;
        allnewurl=‘%s%s%s‘ % (tou, shuzi, wei)
        resalllist = requests.get(allnewurl)
        resalllist.encoding = ‘utf-8‘
        soup_alllist = BeautifulSoup(resalllist.text, ‘html.parser‘)
        for news in soup_alllist.select(‘li‘):
            if len(news.select(‘.news-list-title‘)) > 0:
              # 首页文章标题
              title = news.select(‘.news-list-title‘)[0].text
              # 首页文章链接
              href = news.select(‘a‘)[0][‘href‘]

              print(‘------------------------------------------------------------------------------‘)
              print("文章标题:" + title)
              print("\n文章链接:" + href)

def getClickCount(url):
    HitUrl = ‘http://oa.gzcc.cn/api.php?op=count&id=9183&modelid=80‘
    hitNumber = requests.get(HitUrl).text.split(‘.html‘)[-1].lstrip("(‘").rstrip("‘);")
    print("点击次数:", hitNumber)

    re.match(‘http://news.gzcc.cn/html/2018/xiaoyuanxinwen(.*).html‘, url).group(1).split(‘/‘)[1]
    print(‘新闻编号:‘, re.search(‘\_(.*).html‘, url).group(1))

def getNewDetail(url):  # 获取一页的详细新闻
    res = requests.get(url)
    res.encoding = ‘utf-8‘
    soup = BeautifulSoup(res.text, ‘html.parser‘)

    for news in soup.select(‘li‘):
        if len(news.select(‘.news-list-title‘)) > 0:
            # 首页文章标题
            title = news.select(‘.news-list-title‘)[0].text
            # 首页文章描述
            description = news.select(‘.news-list-description‘)[0].text
            # 首页文章信息
            info = news.select(‘.news-list-info‘)[0].text
            # 首页文章链接
            href = news.select(‘a‘)[0][‘href‘]

            url = href
            res = requests.get(url)
            res.encoding = ‘utf-8‘
            soup = BeautifulSoup(res.text, ‘html.parser‘)

            # 获取每篇文章的信息
            newinfo = soup.select(‘.show-info‘)[0].text

            # 获取文章内容
            content = soup.select(‘#content‘)[0].text

            # 日期
            date = newinfo.split()[0]
            # 当日时间
            time = newinfo.split()[1]
            # 作者
            author = newinfo.split()[2]
            # 审核
            checker = newinfo.split()[3]
            # 来源
            source = newinfo.split()[4]
            # 摄影
            Photography = newinfo.split()[5]

            print(‘------------------------------------------------------------------------------‘)
            print("文章标题:" + title)
            print("\n文章描述:" + description)
            print("\n文章信息:\n" + date + ‘ ‘ + time + ‘\n‘ + author + ‘\n‘ + checker + ‘\n‘ + source + ‘\n‘ + Photography)
            getClickCount(href)  # 点击次数、新闻编号
            print("\n文章链接:" + href)
            print(content)
            print(‘------------------------------------------------------------------------------‘)

# getNewDetail(url)   #获取一页的详细新闻
getlistnew(listnewurl)  # 获取全部的新闻标题链接

#emmm写个死循环就是成刷流量的工具了(滑稽

最后面的:

原文地址:https://www.cnblogs.com/FZW1874402927/p/8777906.html

时间: 2024-08-09 12:47:46

获取全部校园新闻(GZCC大新闻流量刷新器)的相关文章

大新闻!Magic Leap造假,HoloLens即将入华商用

昨天微软搞了大新闻,Terry和Alexi到了深圳,在WinHEC大会上宣布了2017上半年HoloLens正式入华商用. 而唯一竞争对手Magic Leap今天也被曝光其设备造假,各大科技媒体纷纷报道,部分相关报道如下: [新浪科技]Magic Leap被揭底:实际效果不如微软AR 演示视频只是特效 [腾讯科技]Magic Leap被揭穿:所有成果展示全是特效视频 其中新浪科技报道里说“甚至还不如微软的HoloLens”,我只想说小编你牛逼你研发一个啊.你渣浪找不出一个能干的人,给微软的实验室

【python】10分钟教你用python一行代码搞点大新闻

准备 相信各位对python的语言简洁已经深有领会了.那么,今天就带大家一探究竟.看看一行python代码究竟能干些什么大新闻.赶紧抄起手中的家伙,跟我来试试吧. 首先你得先在命令行进入python.像下面一样. 1> python2Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win323Type "help", "copyright&q

获取全部校园新闻(补)

1.取出一个新闻列表页的全部新闻 包装成函数. 2.获取总的新闻篇数,算出新闻总页数. 3.获取全部新闻列表页的全部新闻详情. 4.找一个自己感兴趣的主题,进行数据爬取,并进行分词分析.不能与其它同学雷同. 1-3: import requests from bs4 import BeautifulSoup from datetime import datetime import re listPageUrl = "http://news.gzcc.cn/html/xiaoyuanxinwen/

获取全部校园新闻

1.取出一个新闻列表页的全部新闻 包装成函数. 2.获取总的新闻篇数,算出新闻总页数. 3.获取全部新闻列表页的全部新闻详情. import requests from bs4 import BeautifulSoup from datetime import datetime import re # 获取新闻点击次数 def getNewsId(url): newsId = re.findall(r'\_(.*).html', url)[0][-4:] clickUrl = 'http://o

爬取校园新闻首页的新闻的详情,使用正则表达式,函数抽离

1. 用requests库和BeautifulSoup库,爬取校园新闻首页新闻的标题.链接.正文.show-info. 2. 分析info字符串,获取每篇新闻的发布时间,作者,来源,摄影等信息. 3. 将字符串格式的发布时间转换成datetime类型 4. 使用正则表达式取得新闻编号 5. 生成点击次数的Request URL 6. 获取点击次数 7. 将456步骤定义成一个函数 def getClickCount(newsUrl): 8. 将获取新闻详情的代码定义成一个函数 def getNe

爬取校园新闻首页的新闻

import requests from bs4 import BeautifulSoup from datetime import datetime url="http://news.gzcc.cn/html/xiaoyuanxinwen/" res=requests.get(url) res.encoding="utf-8" soup=BeautifulSoup(res.text,"html.parser") for news in soup

关于Swift的一个大新闻

苹果全新Swfit编程语言虽然发布仅仅几个月,但很多iOS和OS X开发者都表示对Swift的印象不错,这些开发者包括美国航空,Getty Images,LinkedIn(领英)和多邻国(Duolingo).Swift编程语言的优势明显,开发速度更快,完成的应用Bug也更少.与此同时,大家对Swift全新编程语言的兴趣也不断增加. 苹果在去年六月举行的WWDC全球开发者大会上首次公布Swift编程语言,伴随着iOS 8 和OS X Yosemite, Swift也在去年九月正式发布.Swift深

【BZOJ 3652】大新闻 数位dp+期望概率dp

并不难,只是和期望概率dp结合了一下.稍作推断就可以发现加密与不加密是两个互相独立的问题,这个时候我们分开算就好了.对于加密,我们按位统计和就好了;对于不加密,我们先假设所有数都找到了他能找到的最好的匹配(就是异或后为二进制最高位与n-1相等的最大数)并且算出其异或后的总和,然后我们按位贪心,带着所有的数(一开始我们假设所有的数是小于等于二进制最高位与n-1相等的最大数的所有数)从高位走向低位,每走一步,如果这一位是0,就会导致一半的数在这一位不能是1,减去这一半的数在这一位上的贡献,如果这一位

大新闻:delphi 社区版发布(免费全功能)

Delphi Community Edition与自由开发人员,初创公司,学生和非营利组织免费共享,是一个全功能的IDE,用于从单个Delphi代码库(有限的商业使用许可证)构建iOS,Android,Windows和macOS应用程序.Delphi Community Edition包括代码编辑器,强大的调试工具,内置访问流行的本地数据库,设计时具有实时数据,蓝牙和物联网功能以及支持像素完美平台特定样式的可视UI设计器. 特点: 1.免费. 2.全部功能. 3.跨平台. 4.内含数据库. 5.