首页 > 其他分享 >前后端分离,提供蜘蛛爬行最简单方案,创建sitemap xml

前后端分离,提供蜘蛛爬行最简单方案,创建sitemap xml

时间:2024-05-14 13:52:58浏览次数:14  
标签:xml www xxx 爬虫 蜘蛛 Sitemap https sitemap

2024年5月13日11:36:01

现在很多项目是vue react angular开发的,但是百度爬虫对这样的项目支持不好,很多时候回去采用一些 服务器端渲染(SSR)静态站点生成(SSG) ,当然有些框架支持ssr和ssg效果不好,还有些想不不破坏项目自身的提前下的方案呢?

很多年前接手一个angularjs的项目,但是要搞爬虫收录,搞了好久那个时候ssr支持的不太好,所以想了另一个方法。

爬虫是会先爬取 http://127.0.0.1/robots.txt 去读取爬虫规则的,这里面是可以指定stemap xml地址的
例如:

User-agent: *
Allow: /
Sitemap: https://www.xxx.cn/express.xml
Sitemap: https://www.xxx.cn/lastest.xml
Sitemap: https://www.xxx.cn/sitemap1.xml
Sitemap: https://www.xxx.cn/sitemap2.xml
Sitemap: https://www.xxx.cn/sitemap3.xml
Sitemap: https://www.xxx.cn/sitemap4.xml

sitemap规范
https://www.sitemaps.org/protocol.html#index

如果有sitemap的地址,爬虫就会去读取sitemap

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   <url>
      <loc>https://www.xxx.com/page1</loc>
      <lastmod>2023-01-01</lastmod>
      <changefreq>daily</changefreq>
      <priority>0.8</priority>
   </url>
   <url>
      <loc>https://www.xxx.com/page2</loc>
      <lastmod>2023-01-02</lastmod>
      <changefreq>weekly</changefreq>
      <priority>0.6</priority>
   </url>
   <!-- more URLs... -->
</urlset>

那么就可以直接在get的页面的内容接口直接放在地图,让蜘蛛直接获取接口返回的json内容,就不需要渲染,达到让不适用ssr,ssg来让爬虫爬取内容的方法。

laravel支持的sitemap生成工具

composer require spatie/laravel-sitemap

如果内容过多,建议分拆xml文件 Sitemap: https://www.xxx.cn/sitemap4.xml 文件,不然一次太大影响爬虫获取接口返回的时候,注意http头时json格式。

我会去求证一下百度蜘蛛爬虫是否可行,当然我们当年是可以的,因为爬虫技术一直在变,最好找官方支持一下

标签:xml,www,xxx,爬虫,蜘蛛,Sitemap,https,sitemap
From: https://www.cnblogs.com/zx-admin/p/18188910

相关文章

  • 从XML配置角度理解Spring AOP
    本文分享自华为云社区《Spring高手之路18——从XML配置角度理解SpringAOP》,作者:砖业洋__。1.SpringAOP与动态代理1.1SpringAOP和动态代理的关系SpringAOP使用动态代理作为其主要机制来实现面向切面的编程。这种机制允许Spring在运行时动态地创建代理对象,这些代理对象包......
  • 使用nodejs创建返回xml的web server
    //ImportNode.jscoremodulei.ehttpconsthttp=require('http');constfs=require('fs').promises;consthost='localhost';constport=8000;constrssFileName="/news.rss";//Createwebserverconstserve......
  • SpringBoot整合Mybatis时mapper文件和xml文件的位置
    xml文件放在resources下看下我的项目目录2.由于放在resurces下就无法扫描到xml文件,所以就需要在配置文件配置--mapper文件位置mybatis.mapper-locations=classpath:mapper/*.xml或mybatis.mapper-locations=classpath:/mapper/*.xmlxml和mapper文件放在一起我的项目......
  • clickhuose config.xml文件
    <?xmlversion="1.0"?><yandex><logger><level>trace</level><log>/var/log/clickhouse-server/clickhouse-server.log</log><!--日志存放目录--><errorlog>/var/log/clic......
  • Xml和Json在线互转工具
    1、支持将Xml数据转为Json字符串格式2、支持将Json字符串转换为Xml格式的数据3、Json转为Xml数据时,提供自动检测Json格式是否正确,确保转换的Xml数据是准确的4、提供详细的Xml数据和Json字符串数据5、提供示例xml和json示例,供大家测试使用免费使用工具地址:http://tools.linu......
  • XML Schema(XSD)详解:定义 XML 文档结构合法性的完整指南
    XMLSchema描述了XML文档的结构。XMLSchema语言也称为XMLSchemaDefinition(XSD)。 <?xmlversion="1.0"?> <xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema">   <xs:elementname="note"> <xs:compl......
  • XML Schema(XSD)详解:定义 XML 文档结构合法性的完整指南
    XMLSchema描述了XML文档的结构。XMLSchema语言也称为XMLSchemaDefinition(XSD)。<?xmlversion="1.0"?><xs:schemaxmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:elementname="note"><xs:complexType><x......
  • applicationContext.xml
    我真服了,搜了半天没有我想看见的就是关于取代mybatis.xml的文件只能自己写一个了并不能完全取代,至少日志部分还得保留1<?xmlversion="1.0"encoding="UTF-8"?>2<beansxmlns="http://www.springframework.org/schema/beans"3xmlns:xsi="http://www.w3.org/2......
  • Mybatis逆向工程的2种方法,一键高效快速生成Pojo、Mapper、XML,摆脱大量重复开发
    一、写在开头最近一直在更新《Java成长计划》这个专栏,主要是Java全流程学习的一个记录,目前已经更新到Java并发多线程部分,后续会继续更新;而今天准备开设一个全新的专栏《EfficientFarm》。EfficientFarm:高效农场,期许软件开发工作能够像很多国外的高效农场一般机械化,自动化。拿来......
  • python读取xml中的字段值
    importxml.etree.ElementTreeasETxml_string='''<?xmlversion="1.0"encoding="utf-8"?><rssxmlns:atom="http://www.w3.org/2005/Atom"xmlns:media="http://search.yahoo.com/mrss/"......