crawlerdetect

package module
v0.2.33 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 3 Imported by: 11 modules, 9 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

crawlerdetect

CircleCI PkgGoDev

About

crawlerdetect is a Go version of PHP class @CrawlerDetect.

It helps to detect bots/crawlers/spiders via the user agent and other HTTP-headers. Currently able to detect 1,000's of bots/spiders/crawlers.

Installation

go get github.com/x-way/crawlerdetect

Basic Usage

import "fmt"
import "github.com/x-way/crawlerdetect"

func main() {
    uastring := "curl/7.54.0"
    if crawlerdetect.IsCrawler(uastring) {
        fmt.Println("Found a crawler")
    }
}

Contributing

The patterns and testcases are synced from the PHP repo. If you find a bot/spider/crawler user agent that crawlerdetect fails to detect, please submit a pull request with the regex pattern and a testcase to the upstream PHP repo.

Documentation

Overview

Package crawlerdetect provides a Go version of the https://github.com/JayBizzle/Crawler-Detect PHP library It can be used to detect crawlers based on their HTTP User Agent header

Here is a simple example

uastring := "curl/7.54.0"
if crawlerdetect.IsCrawler(uastring) {
        fmt.Println("Found a crawler")
}

To use custom patterns a dedicated instance can be created:

uastring := "curl/7.54.0"
crawlerDetect := crawlerDetect.New()
crawlerDetect.SetCrawlers([]string{`curl`})
if crawlerDetect.IsCrawler(uastring) {
        fmt.Println("Found a crawler")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCrawler

func IsCrawler(input string) bool

IsCrawler checks for a user agent string if it is a crawler

Types

type CrawlerDetect added in v0.2.0

type CrawlerDetect struct {
	// contains filtered or unexported fields
}

CrawlerDetect contains the patterns and exclusions for detecting crawlers

func New added in v0.2.0

func New() *CrawlerDetect

New creates a new CrawlerDetect instance with the default patterns

func (*CrawlerDetect) IsCrawler added in v0.2.0

func (c *CrawlerDetect) IsCrawler(input string) bool

IsCrawler checks for a user agent string if it is a crawler

func (*CrawlerDetect) SetCrawlers added in v0.2.0

func (c *CrawlerDetect) SetCrawlers(crawlers []string)

SetCrawlers sets a custom list of crawler patterns

func (*CrawlerDetect) SetExclusions added in v0.2.0

func (c *CrawlerDetect) SetExclusions(exclusions []string)

SetExclusions sets a custom list of exclusion patterns

Directories

Path Synopsis
cmd
crawlerdetect command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址