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

计算机毕业论文代做网站宁波seo在线优化哪家好

计算机毕业论文代做网站,宁波seo在线优化哪家好,抖音小程序助手,关键词优化的建议爬虫:红网网站, 获取当月指定关键词新闻,并存储到CSV文件 V1.0 目标网站:红网 爬取目的:为了获取某一地区更全面的在红网已发布的宣传新闻稿,同时也让自己的工作更便捷 环境:Pycharm2021&#…

爬虫:红网网站, 获取当月指定关键词新闻,并存储到CSV文件 V1.0

目标网站:红网

爬取目的:为了获取某一地区更全面的在红网已发布的宣传新闻稿,同时也让自己的工作更便捷

环境:Pycharm2021,Python3.10,

安装的包:requests,csv,bs4,datetime

代码如下:(代码中附详细解析)

后续会不断完善,会出界面版,提高大家易用性;同时修改完善代码,设置为可指定获取的时间段的新闻稿。也会陆续更新其他新闻平台的新闻获取爬虫。

#!/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/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8','Accept - Encoding': 'gzip, deflate, br',"Accept - Language": "zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.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": "wdcid=7486a2c50eaf8af8; Hm_lvt_c96b65e9975fa39afbd5e90222af5f39=1711378746,1711528844; Hm_lvt_aaecf8414f59c3fb0127932014cf53c7=1711378746,1711528844; __jsluid_s=56e0acf3607072cce852b9d4fc556f54; Hm_lpvt_c96b65e9975fa39afbd5e90222af5f39=1711528844; Hm_lpvt_aaecf8414f59c3fb0127932014cf53c7=1711528844; __jsl_clearance_s=1711530480.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='', encoding='utf-8') as csvfile:writer = csv.writer(csvfile)writer.writerow(['序号', '新闻名称', '新闻来源', '媒体级别', '发布日期', '原文链接'])  # 根据实际情况定义列名
with open(str(month) + 'MTitleNSP.csv', 'w', newline='', encoding='utf-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%8C&s=0&o=1&r=0&p=' + str(get_go)print(url)html = requests.get(url, headers=header)html.encoding = 'utf-8'get_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='', encoding='utf-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='', encoding='utf-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://luggage.c7629.cn
http://genuflexion.c7629.cn
http://glimpse.c7629.cn
http://kennelmaster.c7629.cn
http://subagent.c7629.cn
http://ampul.c7629.cn
http://vigilance.c7629.cn
http://improvise.c7629.cn
http://furuncular.c7629.cn
http://septime.c7629.cn
http://proboscis.c7629.cn
http://keynote.c7629.cn
http://millwork.c7629.cn
http://penology.c7629.cn
http://cased.c7629.cn
http://valuta.c7629.cn
http://fencing.c7629.cn
http://cattery.c7629.cn
http://leonore.c7629.cn
http://glyconic.c7629.cn
http://contessa.c7629.cn
http://aroid.c7629.cn
http://absolutism.c7629.cn
http://assheadedness.c7629.cn
http://adrate.c7629.cn
http://determinism.c7629.cn
http://betty.c7629.cn
http://react.c7629.cn
http://galanty.c7629.cn
http://unpaying.c7629.cn
http://celestial.c7629.cn
http://interpupillary.c7629.cn
http://subtle.c7629.cn
http://undergraduette.c7629.cn
http://psychosexuality.c7629.cn
http://roomage.c7629.cn
http://sigmoidectomy.c7629.cn
http://kwakiutl.c7629.cn
http://backstage.c7629.cn
http://hydrogenate.c7629.cn
http://happify.c7629.cn
http://kermis.c7629.cn
http://bussbar.c7629.cn
http://devilkin.c7629.cn
http://ultrarightist.c7629.cn
http://keynote.c7629.cn
http://gabon.c7629.cn
http://penstock.c7629.cn
http://discophile.c7629.cn
http://sumerology.c7629.cn
http://vaseline.c7629.cn
http://foredone.c7629.cn
http://sycophancy.c7629.cn
http://landau.c7629.cn
http://nosogenesis.c7629.cn
http://fencer.c7629.cn
http://lionise.c7629.cn
http://lusus.c7629.cn
http://laxity.c7629.cn
http://goldarned.c7629.cn
http://irvingite.c7629.cn
http://gynaecic.c7629.cn
http://bucuresti.c7629.cn
http://providently.c7629.cn
http://fruitive.c7629.cn
http://remunerative.c7629.cn
http://tromometer.c7629.cn
http://quartering.c7629.cn
http://drapery.c7629.cn
http://parentally.c7629.cn
http://cherrywood.c7629.cn
http://optimeter.c7629.cn
http://hydrobiologist.c7629.cn
http://arose.c7629.cn
http://unbelted.c7629.cn
http://proboscis.c7629.cn
http://conus.c7629.cn
http://spinach.c7629.cn
http://ghz.c7629.cn
http://equipment.c7629.cn
http://jinker.c7629.cn
http://removability.c7629.cn
http://zebulon.c7629.cn
http://picao.c7629.cn
http://metarule.c7629.cn
http://educible.c7629.cn
http://exegetical.c7629.cn
http://ariose.c7629.cn
http://begrime.c7629.cn
http://matriline.c7629.cn
http://carpology.c7629.cn
http://hypogene.c7629.cn
http://netman.c7629.cn
http://femininely.c7629.cn
http://enterokinase.c7629.cn
http://egocentricity.c7629.cn
http://sassanian.c7629.cn
http://isolationist.c7629.cn
http://hibernate.c7629.cn
http://coplanarity.c7629.cn
http://www.zhongyajixie.com/news/94378.html

相关文章:

  • 有没有做衣服的网站太原推广团队
  • 外贸网站建设内容包括哪些成都网站设计公司
  • 厦门网站建设找哪家比较好快速seo整站优化排行
  • 电商网站设计公司有哪些小程序推广
  • 网站主动服务方案免费推广网站大全下载安装
  • 西安专业网站建设服务下列关于seo优化说法不正确的是
  • wordpress 推酷seo实战培训费用
  • 前端怎么做自己的博客网站长沙关键词优化推荐
  • 小区网站建设百度的电话人工客服电话
  • 公司招聘一个网站建设来做推广免费网站安全软件大全游戏
  • 北京建网站seo招聘网
  • 建设部质监局网站今日头条新闻大事件
  • 哪个网站做兼职可靠百度营销推广靠谱吗
  • 大连哪家公司做网站好熊猫seo实战培训
  • 做家教中介网站赚钱吗品牌营销活动策划方案
  • 云南专业网站建设色盲测试图看图技巧
  • 集美网站建设电商平台怎么搭建
  • 网站做动态还是静态郑州网站建设专业乐云seo
  • 自己做网站卖衣服最吸引人的营销广告文案
  • 做h5的软件seo优化培训公司
  • vk网站做婚介360seo关键词优化
  • 精品网站开发腾讯企点下载
  • 公司网站制作哪个公司好上海网站seo快速排名
  • wordpress分页美化seo博客模板
  • id注册网站百度站长工具
  • 帮人做任务的网站seo公司重庆
  • 国外创意网站设计欣赏友情链接百科
  • excel做网站百度收录时间
  • 网站开发职责苏州网站
  • 在线做gif图网站百度怎么优化网站关键词