前后端分离项目做爬虫收录,提供蜘蛛爬行最简单方案,创建sitemap xml

2024年5月13日11:36:01

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

参考:https://blog.csdn.net/andy_68147772/article/details/135118183

很多年前接手一个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格式。

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

相关推荐
巴里巴气1 小时前
selenium基础知识 和 模拟登录selenium版本
爬虫·python·selenium·爬虫模拟登录
ddfa12343 小时前
XML 笔记
xml·服务器
一勺菠萝丶1 天前
Spring Boot + MyBatis/MyBatis Plus:XML中循环处理List参数的终极指南
xml·spring boot·mybatis
凛铄linshuo1 天前
爬虫简单实操2——以贴吧为例爬取“某吧”前10页的网页代码
爬虫·python·学习
weixin_416639971 天前
爬虫工程师Chrome开发者工具简单介绍
前端·chrome·爬虫
科技苑2 天前
简单 Python 爬虫程序设计
爬虫
q567315232 天前
R语言初学者爬虫简单模板
开发语言·爬虫·r语言·iphone
泡泡以安3 天前
安卓高版本HTTPS抓包:终极解决方案
爬虫·https·安卓逆向·安卓抓包
q567315233 天前
Java Selenium反爬虫技术方案
java·爬虫·selenium
巴里巴气3 天前
Python爬虫用Clash软件设置代理IP
爬虫·python·tcp/ip