shel / crawler
允许爬取网站地图和节点树
2.4.1
2022-12-14 08:07 UTC
Requires
- php: >=7.4
- ext-curl: *
- ext-libxml: *
- ext-simplexml: *
- chuyskywalker/rolling-curl: ~3.1
- neos/neos: ^5.3 || ^7.3 || ^8.0
README
Neos CMS 节点和网站的爬虫。可用于发布后预热缓存或导出网站为 HTML 文件。
安装
在您的项目中运行以下命令
composer require shel/crawler
使用方法
要基于单个网站地图爬取所有页面,运行
./flow crawler:crawlsitemap --url=http://huve.de.test/sitemap.xml --simultaneousLimit=10 --delay=0
要基于 robots.txt 文件中列出的所有网站地图爬取所有页面,运行
./flow crawler:crawlrobotstxt --url=http://huve.de.test/robots.txt --simultaneousLimit=10 --delay=0
基于节点的爬取
此命令将尝试生成所有页面 HTML,而不使用实际请求,仅内部渲染。由于页面上下文的复杂性,这可能不会得到预期的结果,但所有爬取页面的结果 HTML 可以存储以供进一步使用。
这可以更快,因为所有页面都在一个过程中渲染,并且所有缓存都得到重用。
要使此功能正常工作,您需要提供一个有效的域名。
可以通过以下方式之一完成此操作
- 为网站设置一个活动的域名(推荐,爬虫将使用第一个活动域名)
- 在您的
Settings.yaml
中为 Neos 设置Neos.Flow.http.baseUri
- 通过环境变量
CRAWLER_BASE_URI
提供通用的baseUri
并使用Configuration/Production/Settings.yaml
中的示例
./flow crawler:crawlnodes --siteNodeName <sitename>
基于网站的主要活动域名爬取所有网站
./flow crawler:crawlsites
基于网站的主要活动域名和 robots.txt 中列出的 URL 爬取所有网站
./flow crawler:crawlsites --method robotstxt
实验性静态文件缓存
通过提供 outputPath
,您可以存储所有爬取内容为 HTML 文件。
./flow crawler:crawlnodes --siteNodeName <sitename> --outputPath=Web/cache
您可以通过修改您的 web 服务器配置将其用作一个非常简单的静态文件缓存。以下是一个 nginx 的示例
# Serve a cached page matching the request if it exists location / { default_type "text/html"; try_files /cache/$uri $uri $uri/ /index.php?$args; } # Serve cache/index(.html) instead of / if it exists location = / { default_type "text/html"; try_files /cache/index.html /cache/index /index.php?$args; }
您将现有的 try_files
部分替换为给定的代码,并根据需要调整路径 cache
。此缓存功能是实验性的,您目前负责保持文件更新并删除旧文件。
- 不会清除缓存
- 发布时不会自动更新
- 忽略 Fusion 缓存配置
- 忽略快捷方式(待办事项)
贡献
欢迎贡献或赞助。