实时新闻爬虫

import urllib.request,os,re,random,time
from urllib.error import URLError, HTTPError
l import load_workbook
from openpyxl import Workbook

def mk_dir():
       #创建文件夹
      if not os.path.exists(newspath):
            os.mkdir(newspath)
      if not os.path.exists(newspath+'config\\'):
            os.mkdir(newspath+'config\\')
      if not os.path.exists(newspath + 'config\\adress_dict.xlsx'):
            #预置新闻
            header = ['网站名称','网站地址','新闻地址规则','新闻头',
                            '新闻尾','标题头','标题尾','正文头','段落头',
                            '段落尾']
            url_dict = {'zaobao':'https://www.zaobao.com/realtime/china',
                        'sina':'http://hunan.sina.com.cn',
                        'fenghuang':'http://news.ifeng.com/',
                        'baidu':'http://news.baidu.com/guonei',
                        '163':'http://news.163.com/',
                        'pengbai':'http://www.thepaper.cn/channel_25950'}
            news_addr = {'zaobao':'realtime/china/story'+time.strftime('%Y%m%d',time.localtime())+u'-\d+',
            'sina':'http://hunan.sina.com.cn/news/'+u'./'+time.strftime('%Y-%m-%d',time.localtime())+u'/detail-\D+\d{7}\.shtml',
            'fenghuang':'http://news.ifeng.com'+u'/./'+time.strftime('%Y%m%d',time.localtime())+'/\d{8}_\d\.shtml',
            'baidu':'http://www.thepaper.cn/newsDetail_forward_'+u'\d{7}',
            '163':'http://news.163.com/'+time.strftime('%y/%m%d',time.localtime())+u'/\d\d/\.+\.html',
            'pengbai':'newsDetail_forward_'+u'\d+'}
            news_dict = {'zaobao_begin':'<div class="body-content">','zaobao_end':'<div id="dfp-ad-midarticlespecial-wrapper" class="dfp-tag-wrapper">',
                         'sina_begin':'<div class="article-header clearfix">','sina_end':'<strong class=\'article_erweima_title\'>',
                         'fenghuang_begin':'<div class="yc_ma

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值