crawler-user-agents 1.0.140 → 1.0.142

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,13 +6,15 @@ This repository contains a list of of HTTP user-agents used by robots, crawlers,
6
6
  * Go package: <https://pkg.go.dev/github.com/monperrus/crawler-user-agents>
7
7
  * PyPi package: <https://pypi.org/project/crawler-user-agents/>
8
8
 
9
+ Each `pattern` is a regular expression. It should work out-of-the-box wih your favorite regex library:
10
+
9
11
  ## Install
10
12
 
11
13
  ### Direct download
12
14
 
13
15
  Download the [`crawler-user-agents.json` file](https://raw.githubusercontent.com/monperrus/crawler-user-agents/master/crawler-user-agents.json) from this repository directly.
14
16
 
15
- ### Npm / Yarn
17
+ ### Javascript
16
18
 
17
19
  crawler-user-agents is deployed on npmjs.com: <https://www.npmjs.com/package/crawler-user-agents>
18
20
 
@@ -31,14 +33,21 @@ const crawlers = require('crawler-user-agents');
31
33
  console.log(crawlers);
32
34
  ```
33
35
 
34
- ## Usage
36
+ ### Python
35
37
 
36
- Each `pattern` is a regular expression. It should work out-of-the-box wih your favorite regex library:
38
+ Install with `pip install crawler-user-agents`
39
+
40
+ Then:
41
+
42
+ ```python
43
+ import crawleruseragents
44
+ if crawleruseragents.is_crawler("googlebot/"):
45
+ # do something
46
+ ```
47
+
48
+ ### Go
37
49
 
38
- * JavaScript: `if (RegExp(entry.pattern).test(req.headers['user-agent']) { ... }`
39
- * PHP: add a slash before and after the pattern: `if (preg_match('/'.$entry['pattern'].'/', $_SERVER['HTTP_USER_AGENT'])): ...`
40
- * Python: `if re.search(entry['pattern'], ua): ...`
41
- * Go: use [this package](https://pkg.go.dev/github.com/monperrus/crawler-user-agents),
50
+ Go: use [this package](https://pkg.go.dev/github.com/monperrus/crawler-user-agents),
42
51
  it provides global variable `Crawlers` (it is synchronized with `crawler-user-agents.json`),
43
52
  functions `IsCrawler` and `MatchingCrawlers`.
44
53
 
package/__init__.py ADDED
@@ -0,0 +1,25 @@
1
+ import re
2
+ import json
3
+ from pathlib import Path
4
+
5
+
6
+ def load_json():
7
+ cwd = Path(__file__).parent
8
+ user_agents_file_path = cwd / "crawler-user-agents.json"
9
+ with user_agents_file_path.open() as patterns_file:
10
+ return json.load(patterns_file)
11
+
12
+
13
+ CRAWLER_USER_AGENTS_DATA = load_json()
14
+
15
+
16
+ def is_crawler(user_agent: str) -> bool:
17
+ for crawler_user_agent in CRAWLER_USER_AGENTS_DATA:
18
+ if re.search(crawler_user_agent["pattern"], user_agent, re.IGNORECASE):
19
+ return True
20
+ return False
21
+
22
+
23
+ def is_crawler2(s):
24
+ regexp = re.compile("|".join([i["pattern"] for i in CRAWLER_USER_AGENTS_DATA]))
25
+ return regexp.search(s) is not None
@@ -12,8 +12,7 @@
12
12
  "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
13
13
  "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Safari/537.36"
14
14
  ]
15
- }
16
- ,
15
+ },
17
16
  {
18
17
  "pattern": "Googlebot-Mobile",
19
18
  "instances": [
@@ -5314,5 +5313,11 @@
5314
5313
  "addition_date": "2024/05/14",
5315
5314
  "instances": ["Mozilla/5.0 (compatible; Monsidobot/2.2; +http://monsido.com/bot.html; info@monsido.com)"],
5316
5315
  "url": "http://monsido.com/bot.html"
5316
+ },
5317
+ {
5318
+ "pattern": "GroupMeBot",
5319
+ "addition_date": "2024/05/19",
5320
+ "instances": ["GroupMeBot/1.0"],
5321
+ "url": "https://groupme.com/"
5317
5322
  }
5318
5323
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crawler-user-agents",
3
- "version": "1.0.140",
3
+ "version": "1.0.142",
4
4
  "main": "crawler-user-agents.json",
5
5
  "typings": "./index.d.ts",
6
6
  "author": "Martin Monperrus <martin.monperrus@gnieh.org>",