PHP code example of anassrojea / laracrawler
1. Go to this page and download the library: Download anassrojea/laracrawler library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
anassrojea / laracrawler example snippets
'base_url' => env('APP_URL', 'https://example.com'),
'xdefault' => 'https://example.com', // <xhtml:link hreflang="x-default">
'validate_links' => false,
'max_errors' => 5000,
'exclude_urls' => [
'/admin',
'#\?page=\d+#', // regex pagination
'#/search#',
'#\.(css|js)$#',
],
'exclude_assets' => [
'#\.(css|js|json|xml|txt|md)$#',
'#\.(zip|rar|tar|gz|7z)$#',
],
'normalize' => [
'strip_queries' => true,
'strip_anchors' => true,
'strip_trailing_slash'=> true,
'canonicalize' => true, // lowercase
'enforce_https' => true,
'enforce_www' => null, // true = add, false = strip
'force_trailing_slash'=> false,
],
'default_lang' => 'en',
'lang_mode' => 'path', // "path", "subdomain", or "query"
'alternates' => [
'en' => 'https://example.com/en',
'ar' => 'https://example.com/ar',
'tr' => 'https://example.com/tr',
],
' 'urls' => true,
'images' => true,
'videos' => true,
'languages' => true,
'rules' => [
'#/blog#' => [
'images' => true,
'videos' => false,
],
],
],
'image_whitelist' => [
// '/storage/uploads/services/',
],
'image_defaults' => [
'title' => 'Image Title',
'description' => 'Image Description',
],
'video_whitelist' => [
// '/storage/uploads/services/',
],
'video_defaults' => [
'title' => 'Video Title',
'description' => 'Video Description',
],
'rules' => [
'/$' => [ // homepage
'changefreq' => 'daily',
'priority' => '1.0',
'lastmod' => 'now',
],
'/blog' => [
'changefreq' => 'daily',
'priority' => '0.9',
'priority_boost'=> 0.3, // 🚀 boost blogs slightly
'lastmod' => [
'strategy' => 'db',
'table' => 'posts',
'lookup' => 'slug',
'column' => 'updated_at',
],
],
'#^/(en|ar|tr)?/service#' => [
'changefreq' => 'weekly',
'priority' => null, // auto-score
'priority_boost'=> 0.3, // 🚀 boost services
'lastmod' => [
'strategy' => 'db',
'table' => 'services',
'lookup' => 'slug',
'column' => 'updated_at',
],
],
],
'priority_scoring' => [
'enabled' => true,
'weights' => [
'depth' => 0.4,
'links' => 0.4,
'freshness' => 0.2,
],
'min' => 0.1,
'max' => 1.0,
],
'ping' => true,
'ping_targets' => [
'Google' => 'http://www.google.com/ping?sitemap=',
'Bing' => 'http://www.bing.com/ping?sitemap=',
'Yandex' => 'https://webmaster.yandex.com/ping?sitemap=',
'Baidu' => 'http://ping.baidu.com/ping?sitemap=',
],
'queue' => [
'enabled' => false,
'connection' => 'default',
'batch_size' => 100,
],
'http' => [
'validate_links' => [
'timeout' => 10,
'connect_timeout' => 5,
'verify' => false,
'http_errors' => false,
'headers' => [
'User-Agent' => 'LaracrawlerBot/1.0 (https://example.com)',
],
],
'validate_alternates' => [
'timeout' => 5,
'connect_timeout' => 1,
'verify' => false,
'http_errors' => false,
'headers' => [
'User-Agent' => 'LaracrawlerBot/1.0 (https://example.com)',
],
],
],
'indexability_audit' => true,
bash
php artisan vendor:publish --tag=laracrawler-config
bash
php artisan laracrawler:generate