当前位置: 首页 > news >正文

在线网站制作工具手机网站建设公司哪家好

在线网站制作工具,手机网站建设公司哪家好,博兴建设局网站,phpcmsv9网站地图爬虫#xff1a;红网网站#xff0c; 获取当月指定关键词新闻#xff0c;并存储到CSV文件 V1.0 目标网站#xff1a;红网 爬取目的#xff1a;为了获取某一地区更全面的在红网已发布的宣传新闻稿#xff0c;同时也让自己的工作更便捷 环境#xff1a;Pycharm2021#… 爬虫红网网站 获取当月指定关键词新闻并存储到CSV文件 V1.0 目标网站红网 爬取目的为了获取某一地区更全面的在红网已发布的宣传新闻稿同时也让自己的工作更便捷 环境Pycharm2021Python3.10 安装的包requestscsvbs4datetime 代码如下代码中附详细解析 后续会不断完善会出界面版提高大家易用性同时修改完善代码设置为可指定获取的时间段的新闻稿。也会陆续更新其他新闻平台的新闻获取爬虫。 #!/usr/bin/env python # -*- coding: utf-8 -*- # Time : 2024/3/25 23:05 # Author : LanXiaoFang # Site : # File : redNet.py # Software: PyCharm import csvimport requests from bs4 import BeautifulSoup import datetimeheader {Accept: text/html,application/xhtmlxml,application/xml;q0.9,image/avif,image/webp,*/*;q0.8,Accept - Encoding: gzip, deflate, br,Accept - Language: zh-CN,zh;q0.8,zh-TW;q0.7,zh-HK;q0.5,en-US;q0.3,en;q0.2,Connection: keep - alive,Referer: https://news-search.rednet.cn/Search?q%E5%8F%8C%E7%89%8C,User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0,Cookie: wdcid7486a2c50eaf8af8; Hm_lvt_c96b65e9975fa39afbd5e90222af5f391711378746,1711528844; Hm_lvt_aaecf8414f59c3fb0127932014cf53c71711378746,1711528844; __jsluid_s56e0acf3607072cce852b9d4fc556f54; Hm_lpvt_c96b65e9975fa39afbd5e90222af5f391711528844; Hm_lpvt_aaecf8414f59c3fb0127932014cf53c71711528844; __jsl_clearance_s1711530480.242|1|%2F%2BG2WNMEpLXiwlUgRr2hiMkP%2BMg%3D,Upgrade-Insecure-Requests: 1, }def get_all_indexes(s, char):return [i for i, c in enumerate(s) if c char]# 获取系统时间 now datetime.datetime.now() year now.year # 年 month now.month # 月 day now.day # 日# 创建CSV文件并写入头部信息 with open(str(month) MTitleSP.csv, w, newline, encodingutf-8) as csvfile:writer csv.writer(csvfile)writer.writerow([序号, 新闻名称, 新闻来源, 媒体级别, 发布日期, 原文链接]) # 根据实际情况定义列名 with open(str(month) MTitleNSP.csv, w, newline, encodingutf-8) as csvfile:writer csv.writer(csvfile)writer.writerow([序号, 新闻名称, 新闻来源, 媒体级别, 发布日期, 原文链接]) # 根据实际情况定义列名article_no_sp 1 # 用于计在标题含指定区域的存储的表中的数据的序号 article_no 1 # 用于计在标题不含但内容含指定区域的存储的表中的数据的序号 get_go 0 # 获取第几页开始的数据现在是0开始 count 0 # 用于计算总共爬取的新闻数量 area 双牌 # 爬取指定区域的文章# 相当于满足条件就是一直循环 while get_go 0:url https://news-search.rednet.cn/Search?q%E5%8F%8C%E7%89%8Cs0o1r0p str(get_go)print(url)html requests.get(url, headersheader)html.encoding utf-8get_go 1if html.status_code 200:soups BeautifulSoup(html.text, html.parser)article_info soups.find_all(div, class_result)# print(len(article_info), \n)for i in article_info:result_info i.find_all(div, class_result-info)station_source result_info[0].select(span) # 选择result_info下的所有span标签station_info station_source[0].text # 文章发布站点source_info station_source[1].text # 文章来源print(station_info, source_info)# print(i.find_all(div, class_title), \n)title_info i.find_all(div, class_title)# 文章链接article_href title_info[0].a.get(href)if station_info[3:] area 新闻网:# print(双牌新闻网文章链接, article_href, ---------, https://moment.rednet.cn/pc article_href[22:])article_href https://moment.rednet.cn/pc article_href[22:]# 修改文章来源为红网时刻if rednet in article_href:source_info 红网if moment.rednet in article_href:source_info 红网时刻if 来源 in source_info:source_info station_info[3:]# 文章标题article_title title_info[0].h3.text# 获取发布时间article_up_time title_info[0].span.text# 把显示为进入和昨天的时间改为具体的日期if article_up_time 今天:article_up_time str(year) . str(month) . str(day)elif article_up_time 昨天:article_up_time str(year) . str(month) . str(day - 1)# 修改时间显示格式-替换为.else:# article_up_time article_up_time[:4] . article_up_time[5:7] . article_up_time[8:10] .article_up_time article_up_time.replace(-, .)count 1print(count, ----新闻名称, article_title, 文章来源, source_info, 发布日期, article_up_time, 原文链接,article_href)# 得到这篇文章发布的月份all_index get_all_indexes(article_up_time, .)article_up_time_month article_up_time[all_index[0] 1:all_index[1]]# 只要本月的如果获取到的文章是本月之前的则不再获取,退出循环if int(article_up_time_month) month:print(已经不是这个月的啦, int(article_up_time_month), month)get_go -1break# 把数据存入表格 根据标题是否含有双牌两个字 分开存储if area in article_title:# 这个是标题含有双牌的with open(str(month) MTitleSP.csv, a, newline, encodingutf-8) as csvfile:writer csv.writer(csvfile)writer.writerow([article_no_sp, article_title, source_info, 省级, article_up_time, article_href])article_no_sp 1else:# 这个是标题不含但是内容含有双牌的with open(str(month) MTitleNSP.csv, a, newline, encodingutf-8) as csvfile:writer csv.writer(csvfile)writer.writerow([article_no, article_title, 省级, source_info, article_up_time, article_href])article_no 1由于现在是2024年4月1日 13:04文章更新的本月的不多。 运行结果如下
http://www.dnsts.com.cn/news/195568.html

相关文章:

  • 上海做网站技术那个网站可以看高速的建设情况
  • 网站安全狗 拦截301网站 刷流量 SEO
  • 医院网站建设技术方案ppt网站续费后还是无法访问
  • 电子商务网站的建设报告网站服务器租用怎么购买
  • 如何写网站建设报告怎么做简单的网站首页
  • python整合网站开发技术seo是什么职业
  • 中国十大网站html网页制作步骤
  • 建设部一建注册公示网站四川建设厅官方网站
  • 网站开发需求大吗婚纱摄影网站优化技巧
  • 网站制作公司珠海网站做cdn服务流量
  • 廊坊哪里做网站西安网站注册
  • 开公司做网站vps试用30天
  • 商城网站方案wordpress抖音
  • 深圳建网站seonginx反向代理内网网站建设
  • 建一个公司网站需要几天做网站平台
  • 南昌做购物网站的公司本科自考哪个专业比较好考
  • 开个人网站如何赚钱从代码角度分析网站怎么做
  • 什么是云速建站服务西安微网站建设
  • 北京建站优化公司内蒙古网络
  • 新乡专业做网站公司医院网站和微信公众号建设方案
  • 如何运用链接推广网站wordpress qqworld
  • 专业制作网站价格阜新百姓网
  • 青岛市城市建设局网站wordpress痞子
  • 打开浏览器的网站wordpress 仿站命令
  • 网站建设与制作教案网站建设开票
  • 中小学生在线做试卷的网站6深圳影视广告公司
  • 中山币做网站公司wordpress mx主题VIP
  • 慧聪网怎样做网站友情链接网页视频下载脚本
  • 建站之星有手机版模板望野博物馆官网
  • 网站备案审核河南网站建设首选公司