zoukankan      html  css  js  c++  java
  • 爬取校园新闻首页的新闻

    import requests
    from bs4 import BeautifulSoup
    from datetime import datetime
    
    res=requests.get('http://news.gzcc.cn/html/xiaoyuanxinwen/')
    res.encoding='utf-8'
    soup=BeautifulSoup(res.text,'html.parser')
    
    for news in soup.select('li'):
        if len(news.select('.news-list-title'))>0:
            d = news.select('.news-list-info')[0].contents[0].text
            t = news.select('.news-list-title')[0].text
            href=news.select('a')[0].attrs['href']
    
            resd=requests.get(href)
            resd.encoding='utf-8'
            soupd=BeautifulSoup(resd.text,'html.parser')
    
            ts = soupd.select('#content')[0].text
            infod=soupd.select('.show-info')[0].text
            dt=infod.lstrip('发布时间:')[:19]
            dati = datetime.strptime(dt, '%Y-%m-%d %H:%M:%S')
            ther=infod[infod.find('作者:'):infod.find('审核:')].split()[0].lstrip('作者:')
            source = infod[infod.find('来源:'):].split()[0].lstrip('来源:')
            photo = infod[infod.find('摄影:'):].split()[0].lstrip('摄影:')
            print(dati, dati.strftime('%Y/%m/%d'))
            #print(dt,ther,source,)
    

      

  • 相关阅读:
    1.3.9、通过权重 Weight匹配
    1.3.8、通过RemoteAddr匹配
    1.3.7、通过QueryParam匹配
    1.3.6、通过Path匹配
    1.3.5、通过Method匹配
    1.3.4、通过Host匹配
    css选择器优先级如何计算
    pm2常用命令
    前端微服务 二
    前端微服务
  • 原文地址:https://www.cnblogs.com/polvem/p/8711718.html
Copyright © 2011-2022 走看看