前后端分离项目做爬虫收录,提供蜘蛛爬行最简单方案,创建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格式。

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

相关推荐
祭曦念5 小时前
ArkUI声明式UI入门:从XML到声明式的思维转变
xml·ui·鸿蒙
Smartdaili China17 小时前
OpenClaw赋能AI智能体:实时联网与网页抓取
人工智能·爬虫·ai·爬取·openclaw·open claw
IP搭子来一个1 天前
爬虫使用代理 IP 频繁失效,该如何定位问题?
网络·爬虫·tcp/ip
weixin_468466851 天前
Crawl4Ai 智能数据采集与场景化应用指南
大数据·人工智能·爬虫·python·数据分析
小熊Coding2 天前
Python爬取当当网二手图书项目实战!
开发语言·爬虫·python·beautifulsoup·requests·二手图书
Meteors.2 天前
安卓源码阅读——01.grade设置binding为true时,xml如何进行映射
android·xml
IP搭子来一个2 天前
爬虫采集大量返回 403、429,到底卡在哪一环?
网络·爬虫·python
小白学大数据2 天前
Playwright 爬虫:Python 爬取 JS 渲染的 JSP 网站
开发语言·javascript·爬虫·python·数据分析
程序员buddha2 天前
传统 Spring 框架,XML 配置 Bean 的方式
xml·java·spring
遇事不決洛必達2 天前
【爬虫随笔】常见加密算法特征总结
javascript·爬虫·逆向·加密算法