Configuring the crawler | laravel-sitemap-rust | Spatie       

 SPATIE  

laravel-sitemap-rust
====================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-sitemap-rust](https://spatie.be/docs/laravel-sitemap-rust/v1)  Customizing-the-crawler  Configuring the crawler

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-sitemap-rust/v1) 

  Configuring the crawler    
- [ Introduction ](https://spatie.be/docs/laravel-sitemap-rust/v1/introduction)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-sitemap-rust/v1/installation-setup)
- [ Support us ](https://spatie.be/docs/laravel-sitemap-rust/v1/support-us)
- [ Changelog ](https://spatie.be/docs/laravel-sitemap-rust/v1/changelog)
- [ Questions and issues ](https://spatie.be/docs/laravel-sitemap-rust/v1/questions-issues)
- [ Testing ](https://spatie.be/docs/laravel-sitemap-rust/v1/testing)
- [ About us ](https://spatie.be/docs/laravel-sitemap-rust/v1/about-us)

Creating sitemaps
-----------------

- [ Generating a sitemap ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/generating-a-sitemap)
- [ Manually creating a sitemap ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/manually-creating-a-sitemap)
- [ Creating a sitemap index ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/creating-a-sitemap-index)
- [ Splitting large sitemaps ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/splitting-large-sitemaps)
- [ Grouping URLs into multiple sitemaps ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/grouping-urls-into-multiple-sitemaps)
- [ Adding an XSL stylesheet ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/adding-an-xsl-stylesheet)
- [ Returning a response ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/returning-a-response)
- [ Sorting URLs ](https://spatie.be/docs/laravel-sitemap-rust/v1/creating-sitemaps/sorting-urls)

Customizing the crawler
-----------------------

- [ Crawl profiles ](https://spatie.be/docs/laravel-sitemap-rust/v1/customizing-the-crawler/crawl-profiles)
- [ Filtering URLs ](https://spatie.be/docs/laravel-sitemap-rust/v1/customizing-the-crawler/filtering-urls)
- [ Configuring the crawler ](https://spatie.be/docs/laravel-sitemap-rust/v1/customizing-the-crawler/configuring-the-crawler)

Adding content to URLs
----------------------

- [ Alternates ](https://spatie.be/docs/laravel-sitemap-rust/v1/adding-content-to-urls/alternates)
- [ Images ](https://spatie.be/docs/laravel-sitemap-rust/v1/adding-content-to-urls/images)
- [ Videos ](https://spatie.be/docs/laravel-sitemap-rust/v1/adding-content-to-urls/videos)
- [ News ](https://spatie.be/docs/laravel-sitemap-rust/v1/adding-content-to-urls/news)
- [ Sitemapable models ](https://spatie.be/docs/laravel-sitemap-rust/v1/adding-content-to-urls/sitemapable-models)

Advanced usage
--------------

- [ Scheduled generation ](https://spatie.be/docs/laravel-sitemap-rust/v1/advanced-usage/scheduled-generation)
- [ Writing to disks ](https://spatie.be/docs/laravel-sitemap-rust/v1/advanced-usage/writing-to-disks)
- [ Handling errors ](https://spatie.be/docs/laravel-sitemap-rust/v1/advanced-usage/handling-errors)

 Configuring the crawler
=======================

###  On this page 

1. [ Limiting the amount of pages crawled ](#content-limiting-the-amount-of-pages-crawled)
2. [ Setting the crawl concurrency ](#content-setting-the-crawl-concurrency)
3. [ Controlling the crawl depth ](#content-controlling-the-crawl-depth)
4. [ Executing JavaScript ](#content-executing-javascript)

- Use `configure_crawler` for transport settings from the [crawler API](https://docs.rs/spatie-crawler).
- Return the configured builder from the callback. For example, disable robots.txt checks:

```
use spatie_sitemap::SitemapGenerator;
SitemapGenerator::new("https://example.com")?
    .configure_crawler(|crawler| {
        Ok(crawler.respect_robots(false))
    })
    .write_to_file(&sitemap_path).await?;
```

Limiting the amount of pages crawled
--------------------------------------------------------------------------------------------------------------------------------------------------------------------

You can limit the amount of pages crawled by calling `set_maximum_crawl_count`:

```
SitemapGenerator::new("https://example.com")?
    .set_maximum_crawl_count(500)
    .write_to_file(&sitemap_path).await?;
```

Setting the crawl concurrency
-----------------------------------------------------------------------------------------------------------------------------------------------

You can set the number of concurrent connections the crawler will use:

```
SitemapGenerator::new("https://example.com")?
    .set_concurrency(1)
    .write_to_file(&sitemap_path).await?;
```

The default concurrency is 10.

Controlling the crawl depth
-----------------------------------------------------------------------------------------------------------------------------------------

You can limit how deep the crawler follows links:

```
SitemapGenerator::new("https://example.com")?
    .configure_crawler(|crawler| {
        Ok(crawler.max_depth(3))
    })
    .write_to_file(&path).await?;
```

Executing JavaScript
--------------------------------------------------------------------------------------------------------------------

The sitemap generator can execute JavaScript on each page so it will discover links that are generated by your JS scripts. You can enable this feature by setting `execute_javascript` to `true`:

```
use spatie_sitemap::{SitemapConfig, SitemapGenerator};

let generator = SitemapGenerator::new("https://example.com")?
    .with_config(SitemapConfig {
        execute_javascript: true,
        ..Default::default()
    });
```

Under the hood, headless Chromium is used to execute JavaScript. Install Chrome or Chromium on your system; no Node installation is needed.

The package will make an educated guess as to where Chrome is installed on your system. You can also set `chrome_binary_path` in `SitemapConfig`.

Only render trusted pages or run Chromium with isolated networking. Chromium can load resources outside the crawl profile's navigation scope; a profile is not a browser sandbox. The default renderer keeps Chromium's OS sandbox enabled.

Private-network HTTP requests are disabled by default. Set `allow_private_networks` only for trusted local or intranet crawls. Individual HTTP failures are omitted from the sitemap; attach an `on_event` callback through `configure_crawler` to observe them. Invalid crawler configuration and crawl-wide failures return errors.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
