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

把网站做app百度注册公司地址

把网站做app,百度注册公司地址,网站维护推广表,chrome浏览器官网入口python爬虫(五)之新出行汽车爬虫 接完最后一单,终于肝完了最后一个python爬虫——新出行爬虫,将https://www.xchuxing.com网站上所有的汽车爬虫全部抓取下来。 import requests import json import csv from lxml import etree …

python爬虫(五)之新出行汽车爬虫

接完最后一单,终于肝完了最后一个python爬虫——新出行爬虫,将https://www.xchuxing.com网站上所有的汽车爬虫全部抓取下来。

import requests
import json
import csv
from lxml import etree
import timeclass Xchuxing:def __init__(self):self.article_list_pre_url = "https://www.xchuxing.com/official?category=1&page="self.start_page = 1self.end_page = 1000self.payload = {}self.article_list_headers = {'Accept': 'application/json, text/plain, */*','Accept-Language': 'zh-CN,zh;q=0.9','Cache-Control': 'no-cache','Connection': 'keep-alive','Cookie': 'community_new_sort=22af645d1859cb5ca6da0c484f1f37ea; Hm_lvt_55f107d825a4c4e989d543a8bf935508=1710252997; Hm_lpvt_55f107d825a4c4e989d543a8bf935508=1710253296','Referer': 'https://www.xchuxing.com/official','Sec-Fetch-Dest': 'empty','Sec-Fetch-Mode': 'cors','Sec-Fetch-Site': 'same-origin','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36','X-Requested-With': 'XMLHttpRequest','sec-ch-ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"','sec-ch-ua-mobile': '?0','sec-ch-ua-platform': '"Windows"'}self.article_detail_headers = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7','Accept-Language': 'zh-CN,zh;q=0.9','Cache-Control': 'max-age=0','Connection': 'keep-alive','Cookie': 'community_new_sort=22af645d1859cb5ca6da0c484f1f37ea; Hm_lvt_55f107d825a4c4e989d543a8bf935508=1710252997; Hm_lpvt_55f107d825a4c4e989d543a8bf935508=1710255840','Referer': 'https://www.xchuxing.com/official','Sec-Fetch-Dest': 'document','Sec-Fetch-Mode': 'navigate','Sec-Fetch-Site': 'same-origin','Sec-Fetch-User': '?1','Upgrade-Insecure-Requests': '1','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36','sec-ch-ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Google Chrome";v="122"','sec-ch-ua-mobile': '?0','sec-ch-ua-platform': '"Windows"'}def get_request(self, url, headers):response = requests.request("GET", url, headers=headers, data=self.payload)return response.textdef do_work(self):with open('新出行.csv', 'w', newline='', encoding='utf-8-sig') as file:writer = csv.writer(file)csv_title = ["标题", "作者", "发布时间", "正文"]writer.writerow(csv_title)for current_page in range(self.start_page, self.end_page):print("================> 当前第" + str(current_page) + "页,共" + str(self.end_page) + "页 ============")article_list_url = self.article_list_pre_url + str(current_page)text = self.get_request(article_list_url, headers=self.article_list_headers)data = json.loads(text)["data"]self.write_page(writer, data)def write_page(self, writer, data):for item in data:# print(item["title"])# print(item["author"]["username"])# print(item["created_at"])# 获取文章详情内容# https://www.xchuxing.com/article/116378article_url = "https://www.xchuxing.com/article/" + str(item["object_id"])text = self.get_request(article_url, headers=self.article_detail_headers)html = etree.HTML(text)result = html.xpath("normalize-space(//div[@class='content-main']/div[5])")# print(result)time_struct = time.localtime(item["created_at"])date = time.strftime("%Y-%m-%d %H:%M:%S", time_struct)row = [item["title"], item["author"]["username"], date, result]writer.writerow(row)print("===========> 当前文章 " + article_url + " 写入完毕", )if __name__ == '__main__':xchuxing = Xchuxing()xchuxing.do_work()

运行结果:
image-20240513234912727

写在最后

代码精选(www.codehuber.com),程序员的终身学习网站已上线!

如果这篇【文章】有帮助到你,希望可以给【JavaGPT】点个赞👍,创作不易,如果有对【后端技术】、【前端领域】感兴趣的小可爱,也欢迎关注❤️❤️❤️ 【JavaGPT】❤️❤️❤️,我将会给你带来巨大的【收获与惊喜】💝💝💝!

http://www.khdw.cn/news/17444.html

相关文章:

  • 动态效果酷炫的网站自助建站免费建站平台
  • 公安局网站建设规划书东莞做网站seo
  • 信丰县建设局网站网站检测中心
  • 做旅游网站的yi百度统计数据
  • 网站源码做exe执行程序软文推广收费
  • 商会网站怎么做公司推广方法有哪些
  • 整个网站的关键词泉州全网推广
  • 手机建设银行官方网站短视频seo询盘获客系统
  • 合工大智能院网站建设线上营销平台有哪些
  • 做网站设计管理的专业深圳网络整合营销公司
  • 潍坊做网站优化网店推广营销方案
  • 梧州专业网站推广免费行情网站
  • 做设计哪个网站可以接单cms自助建站系统
  • 南京建站公司深圳小程序建设公司
  • 长沙城乡建设网站知名品牌营销案例100例
  • 做淘宝美工需要知道的网站网站设计模板网站
  • 外包一个企业网站多少钱windows优化大师靠谱吗
  • php做网站如何seo的中文含义是
  • 业务员自己掏钱做网站可以吗上海优化seo
  • 宁波网站建设就业方向如何在百度上营销
  • 保健品网站可以做网站培训心得体会100字
  • 最好的网站设计公司源码 php详细的营销推广方案
  • 机关党建项目网站建设方案免费网站搭建平台
  • 电子商务网站建设策划说aso优化app推广
  • 做电影网站要怎么拿到版权百度app安装免费下载
  • seo网站三要素怎么做by网站域名
  • 湛江优化网站排名如何做百度竞价推广
  • 诸暨网站制作个人推广app的妙招
  • 深圳市网站建设公司seo怎么弄
  • 九江开发区建设规划局网站百度竞价排名名词解释