google-img-scrap 1.0.6 → 1.0.7
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/CHANGELOG.md +3 -0
- package/README.md +113 -53
- package/package.json +2 -2
- package/src/utils/UTILS.js +4 -4
- package/test/test.js +0 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Google-img-scrap v1.0.
|
|
1
|
+
# Google-img-scrap v1.0.7
|
|
2
2
|
|
|
3
|
-
Scrap images from google
|
|
3
|
+
Scrap images from google images with customs pre filled options
|
|
4
4
|
|
|
5
5
|
## Update
|
|
6
6
|
|
|
@@ -18,68 +18,93 @@ npm i google-img-scrap
|
|
|
18
18
|
|
|
19
19
|
## Import
|
|
20
20
|
|
|
21
|
-
- NPM
|
|
22
|
-
|
|
23
21
|
```js
|
|
24
22
|
const { GOOGLE_IMG_SCRAP , GOOGLE_QUERY } = require('google-img-scrap');
|
|
25
23
|
```
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
```js
|
|
30
|
-
const { GOOGLE_IMG_SCRAP , GOOGLE_QUERY } = require('./src/google-img-scrap');
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Params
|
|
25
|
+
## Query Params
|
|
34
26
|
|
|
35
27
|
- "search" (String) what you want to search
|
|
36
28
|
- "execute" (Function) allow you to execute a function to remove "gstatic.com" domains for example
|
|
37
|
-
- "excludeWords" (
|
|
38
|
-
- "domains" (
|
|
39
|
-
- "excludeDomains" (
|
|
29
|
+
- "excludeWords" (String[]) exclude some words from the search
|
|
30
|
+
- "domains" (String[]) filter by domains
|
|
31
|
+
- "excludeDomains" (String[]) exclude some domains
|
|
40
32
|
- "safeSearch" (Boolean) active safe search or not for nsfw for example
|
|
41
33
|
- "custom" (String) add extra query
|
|
42
|
-
- "urlMatch" (
|
|
43
|
-
- "filterByTitles" (
|
|
34
|
+
- "urlMatch" (String[][]) get image when an url match a string (example: "cdn") | ```example below```
|
|
35
|
+
- "filterByTitles" (String[][]) filter images by titles | ```example below```
|
|
44
36
|
- "query" (Object) set a query (can be [TYPE, DATE, COLOR, SIZE, LICENCE, EXTENSION]) (use GOOGLE_QUERY items | ```example below```
|
|
45
37
|
- "limit" (Int) to limit the size of the results
|
|
46
38
|
|
|
47
39
|
## Result
|
|
48
40
|
|
|
49
41
|
```js
|
|
50
|
-
}
|
|
51
42
|
{
|
|
52
|
-
url: 'https://images.google.com/search?tbm=isch&tbs=itp:clipart,qdr:y,ic:gray,isz:l,il:ol,ift:jpg&q=cats',
|
|
43
|
+
url: 'https://images.google.com/search?tbm=isch&tbs=itp:clipart,qdr:y,ic:gray,isz:l,il:ol,ift:jpg&q=cats%20%20%20-%22black%22%20-%22white%22&name=content&name2=content2',
|
|
53
44
|
result: [
|
|
54
45
|
{
|
|
55
|
-
url: 'https://media.
|
|
56
|
-
height: '
|
|
46
|
+
url: 'https://media.gettyimages.com/vectors/cat-eating-fish-vector-id1216628506',
|
|
47
|
+
height: '1024',
|
|
57
48
|
width: '1024'
|
|
58
49
|
},
|
|
59
50
|
{
|
|
60
|
-
url: 'https://
|
|
61
|
-
height: '
|
|
51
|
+
url: 'https://www.ariatrade.gr/images/products/2021/10/110294_1.jpg',
|
|
52
|
+
height: '768',
|
|
62
53
|
width: '1024'
|
|
63
54
|
},
|
|
64
55
|
{
|
|
65
|
-
url: 'https://media.
|
|
66
|
-
height: '
|
|
56
|
+
url: 'https://media.gettyimages.com/illustrations/panther-leaping-illustration-id152406879?s=2048x2048',
|
|
57
|
+
height: '2048',
|
|
67
58
|
width: '2048'
|
|
68
59
|
},
|
|
69
|
-
|
|
60
|
+
{
|
|
61
|
+
url: 'https://media.gettyimages.com/illustrations/botany-plants-antique-engraving-illustration-erythrina-variegata-illustration-id970781520',
|
|
62
|
+
height: '1024',
|
|
63
|
+
width: '828'
|
|
64
|
+
}
|
|
70
65
|
]
|
|
66
|
+
...
|
|
71
67
|
}
|
|
72
68
|
```
|
|
73
69
|
|
|
74
70
|
## How to use ?
|
|
75
71
|
|
|
76
|
-
- For the query parameter you need to set the name in upper case
|
|
72
|
+
- **For the query parameter you need to set the name in upper case !**
|
|
73
|
+
|
|
74
|
+
## Simple example
|
|
75
|
+
|
|
76
|
+
Search cats images
|
|
77
77
|
|
|
78
78
|
```js
|
|
79
|
-
|
|
79
|
+
(async function(){
|
|
80
|
+
const test = await GOOGLE_IMG_SCRAP({
|
|
81
|
+
search: "cats",
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
console.log(test);
|
|
85
|
+
})();
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Removing gstatic.com
|
|
89
|
+
|
|
90
|
+
```js
|
|
91
|
+
(async function(){
|
|
92
|
+
const test = await GOOGLE_IMG_SCRAP({
|
|
93
|
+
search: "demon slayer background hd",
|
|
94
|
+
execute: function(element){
|
|
95
|
+
if(!element.url.match('gstatic.com')) return element;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
console.log(test);
|
|
100
|
+
})();
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Custom query
|
|
80
104
|
|
|
81
|
-
|
|
105
|
+
All query options are optional (see below for all the options)
|
|
82
106
|
|
|
107
|
+
```js
|
|
83
108
|
(async function(){
|
|
84
109
|
const test = await GOOGLE_IMG_SCRAP({
|
|
85
110
|
search: "cats",
|
|
@@ -91,51 +116,91 @@ console.log(GOOGLE_QUERY);
|
|
|
91
116
|
LICENCE: GOOGLE_QUERY.LICENCE.COMMERCIAL_AND_OTHER,
|
|
92
117
|
EXTENSION: GOOGLE_QUERY.EXTENSION.JPG
|
|
93
118
|
},
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
console.log(test);
|
|
122
|
+
})();
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Limit result size
|
|
126
|
+
|
|
127
|
+
```js
|
|
128
|
+
(async function(){
|
|
129
|
+
const test = await GOOGLE_IMG_SCRAP({
|
|
130
|
+
search: "cats",
|
|
94
131
|
limit: 5,
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
console.log(test);
|
|
135
|
+
})();
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Domains
|
|
139
|
+
|
|
140
|
+
Only scrap from a specific domain
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
(async function(){
|
|
144
|
+
const test = await GOOGLE_IMG_SCRAP({
|
|
145
|
+
search: "cats",
|
|
95
146
|
domains: ["alamy.com", "istockphoto.com", "vecteezy.com"],
|
|
96
|
-
excludeWords: ["black", "white"], //If you don't like black and white cats
|
|
97
|
-
custom: "name=content&name2=content2",
|
|
98
|
-
safeSearch: false,
|
|
99
|
-
// excludeDomains: ["istockphoto.com", "alamy.com"]
|
|
100
147
|
});
|
|
101
148
|
|
|
102
|
-
console.log(test
|
|
149
|
+
console.log(test);
|
|
103
150
|
})();
|
|
104
151
|
```
|
|
105
152
|
|
|
106
|
-
|
|
153
|
+
## Exclude domains
|
|
107
154
|
|
|
108
155
|
```js
|
|
109
|
-
|
|
156
|
+
(async function(){
|
|
157
|
+
const test = await GOOGLE_IMG_SCRAP({
|
|
158
|
+
search: "cats",
|
|
159
|
+
excludeDomains: ["istockphoto.com", "alamy.com"]
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
console.log(test);
|
|
163
|
+
})();
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Exclude words
|
|
110
167
|
|
|
168
|
+
If you don' like black cats and white cats
|
|
169
|
+
|
|
170
|
+
```js
|
|
111
171
|
(async function(){
|
|
112
172
|
const test = await GOOGLE_IMG_SCRAP({
|
|
113
173
|
search: "cats",
|
|
174
|
+
excludeWords: ["black", "white"], //If you don't like black cats and white cats
|
|
114
175
|
});
|
|
115
176
|
|
|
116
177
|
console.log(test, test.result.length);
|
|
117
178
|
})();
|
|
118
179
|
```
|
|
119
180
|
|
|
120
|
-
##
|
|
181
|
+
## Safe search (no nsfw)
|
|
121
182
|
|
|
122
183
|
```js
|
|
123
|
-
const { GOOGLE_IMG_SCRAP , GOOGLE_QUERY } = require('google-img-scrap');
|
|
124
|
-
|
|
125
184
|
(async function(){
|
|
126
185
|
const test = await GOOGLE_IMG_SCRAP({
|
|
127
|
-
search: "
|
|
128
|
-
query: {
|
|
129
|
-
SIZE: GOOGLE_QUERY.SIZE.LARGE,
|
|
130
|
-
},
|
|
131
|
-
domains: ["alphacoders.com"],
|
|
186
|
+
search: "cats",
|
|
132
187
|
safeSearch: false,
|
|
133
|
-
execute: function(element){
|
|
134
|
-
if(!element.url.match('gstatic.com')) return element;
|
|
135
|
-
}
|
|
136
188
|
});
|
|
137
189
|
|
|
138
|
-
console.log(test
|
|
190
|
+
console.log(test);
|
|
191
|
+
})();
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Custom query params
|
|
195
|
+
|
|
196
|
+
```js
|
|
197
|
+
(async function(){
|
|
198
|
+
const test = await GOOGLE_IMG_SCRAP({
|
|
199
|
+
search: "cats",
|
|
200
|
+
custom: "name=content&name2=content2",
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
console.log(test);
|
|
139
204
|
})();
|
|
140
205
|
```
|
|
141
206
|
|
|
@@ -144,8 +209,6 @@ const { GOOGLE_IMG_SCRAP , GOOGLE_QUERY } = require('google-img-scrap');
|
|
|
144
209
|
- urlMatch work like filterByTiles
|
|
145
210
|
|
|
146
211
|
```js
|
|
147
|
-
const { GOOGLE_IMG_SCRAP } = require('google-img-scrap');
|
|
148
|
-
|
|
149
212
|
(async function(){
|
|
150
213
|
const test = await GOOGLE_IMG_SCRAP({
|
|
151
214
|
search: "cats",
|
|
@@ -154,12 +217,9 @@ const { GOOGLE_IMG_SCRAP } = require('google-img-scrap');
|
|
|
154
217
|
["draw", "white"],
|
|
155
218
|
["albino", "white"]
|
|
156
219
|
],
|
|
157
|
-
execute: function(element){
|
|
158
|
-
if(!element.url.match('gstatic.com')) return element;
|
|
159
|
-
}
|
|
160
220
|
});
|
|
161
221
|
|
|
162
|
-
console.log(test
|
|
222
|
+
console.log(test);
|
|
163
223
|
})();
|
|
164
224
|
```
|
|
165
225
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "google-img-scrap",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Scrap images from google images with
|
|
3
|
+
"version": "1.0.7",
|
|
4
|
+
"description": "Scrap images from google images with customs pre filled options",
|
|
5
5
|
"main": "./src/google-img-scrap.js",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
7
7
|
"directories": {
|
package/src/utils/UTILS.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
function buildQuery(query, translator){
|
|
2
|
-
|
|
2
|
+
const result = [];
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const params = Object.keys(query);
|
|
5
|
+
const toTranslate = Object.keys(translator);
|
|
6
6
|
|
|
7
7
|
for(const param of params){
|
|
8
|
-
|
|
8
|
+
const queryName = param;
|
|
9
9
|
if(toTranslate.includes(param)) queryName = toTranslate[param];
|
|
10
10
|
|
|
11
11
|
result.push(`${queryName}=${query[param]}`);
|
package/test/test.js
CHANGED
|
@@ -13,7 +13,6 @@ const { GOOGLE_IMG_SCRAP , GOOGLE_QUERY } = require('../src/google-img-scrap');
|
|
|
13
13
|
LICENCE: GOOGLE_QUERY.LICENCE.COMMERCIAL_AND_OTHER,
|
|
14
14
|
EXTENSION: GOOGLE_QUERY.EXTENSION.JPG
|
|
15
15
|
},
|
|
16
|
-
domains: ["alamy.com", "istockphoto.com", "vecteezy.com"],
|
|
17
16
|
excludeWords: ["black", "white"], //If you don't like black and white cats
|
|
18
17
|
custom: "name=content&name2=content2",
|
|
19
18
|
safeSearch: false,
|