crawler-user-agents 1.0.140 → 1.0.141
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 +16 -7
- package/__init__.py +22 -0
- package/package.json +1 -1
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
|
-
###
|
|
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
|
-
|
|
36
|
+
### Python
|
|
35
37
|
|
|
36
|
-
|
|
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
|
-
|
|
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,22 @@
|
|
|
1
|
+
import crawleruseragents
|
|
2
|
+
import re
|
|
3
|
+
import json
|
|
4
|
+
from importlib import resources
|
|
5
|
+
|
|
6
|
+
def load_json():
|
|
7
|
+
return json.loads(resources.read_text(crawleruseragents,"crawler-user-agents.json"))
|
|
8
|
+
|
|
9
|
+
DATA = load_json()
|
|
10
|
+
|
|
11
|
+
def is_crawler(s):
|
|
12
|
+
# print(s)
|
|
13
|
+
for i in DATA:
|
|
14
|
+
test=re.search(i["pattern"],s,re.IGNORECASE)
|
|
15
|
+
if test:
|
|
16
|
+
return True
|
|
17
|
+
return False
|
|
18
|
+
|
|
19
|
+
def is_crawler2(s):
|
|
20
|
+
regexp = re.compile("|".join([i["pattern"] for i in DATA]))
|
|
21
|
+
return regexp.search(s) != None
|
|
22
|
+
|