triangle-utils 1.4.4 → 1.4.6
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/dist/src/UtilsBee.d.ts +1 -0
- package/dist/src/UtilsBee.js +21 -15
- package/package.json +1 -1
- package/src/UtilsBee.ts +23 -15
package/dist/src/UtilsBee.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export declare class UtilsBee {
|
|
|
2
2
|
private readonly bee;
|
|
3
3
|
private readonly text_decoder;
|
|
4
4
|
constructor(scraping_bee_api_key: string | undefined);
|
|
5
|
+
get_buffer(url: string, params?: Record<string, string | number | boolean>): Promise<Buffer<any> | undefined>;
|
|
5
6
|
get(url: string, params?: Record<string, string | number | boolean>): Promise<string | undefined>;
|
|
6
7
|
google_search(query: string, news?: boolean): Promise<Record<string, any>[] | undefined>;
|
|
7
8
|
youtube_search(query: string, options?: {}): Promise<Record<string, any>[] | undefined>;
|
package/dist/src/UtilsBee.js
CHANGED
|
@@ -6,29 +6,35 @@ export class UtilsBee {
|
|
|
6
6
|
this.bee = scraping_bee_api_key !== undefined ? new ScrapingBeeClient(scraping_bee_api_key) : undefined;
|
|
7
7
|
this.text_decoder = new TextDecoder();
|
|
8
8
|
}
|
|
9
|
-
async
|
|
9
|
+
async get_buffer(url, params = {}) {
|
|
10
10
|
if (this.bee === undefined) {
|
|
11
11
|
return undefined;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return text;
|
|
13
|
+
try {
|
|
14
|
+
const response = await this.bee.htmlApi({
|
|
15
|
+
url: url,
|
|
16
|
+
params: params
|
|
17
|
+
});
|
|
18
|
+
if (response.data instanceof Buffer) {
|
|
19
|
+
return response.data;
|
|
21
20
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
console.log(
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
if (error instanceof Error) {
|
|
25
|
+
console.log(error.stack);
|
|
27
26
|
}
|
|
27
|
+
console.log("Failed to get from Scraping Bee.");
|
|
28
28
|
}
|
|
29
|
-
console.log("Failed to get from Scraping Bee, quitting.");
|
|
30
29
|
return undefined;
|
|
31
30
|
}
|
|
31
|
+
async get(url, params = {}) {
|
|
32
|
+
const buffer = await this.get_buffer(url, params);
|
|
33
|
+
if (buffer === undefined) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
return this.text_decoder.decode(buffer);
|
|
37
|
+
}
|
|
32
38
|
async google_search(query, news = false) {
|
|
33
39
|
if (this.bee === undefined) {
|
|
34
40
|
return undefined;
|
package/package.json
CHANGED
package/src/UtilsBee.ts
CHANGED
|
@@ -10,27 +10,35 @@ export class UtilsBee {
|
|
|
10
10
|
this.text_decoder = new TextDecoder()
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
async
|
|
13
|
+
async get_buffer(url : string, params : Record<string, string | number | boolean> = {}) {
|
|
14
14
|
if (this.bee === undefined) {
|
|
15
15
|
return undefined
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
console.log("Failed to get from Scraping Bee.")
|
|
17
|
+
try {
|
|
18
|
+
const response = await this.bee.htmlApi({
|
|
19
|
+
url : url,
|
|
20
|
+
params : params
|
|
21
|
+
})
|
|
22
|
+
if (response.data instanceof Buffer) {
|
|
23
|
+
return response.data
|
|
24
|
+
}
|
|
25
|
+
return undefined
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (error instanceof Error) {
|
|
28
|
+
console.log(error.stack)
|
|
30
29
|
}
|
|
30
|
+
console.log("Failed to get from Scraping Bee.")
|
|
31
31
|
}
|
|
32
|
-
console.log("Failed to get from Scraping Bee, quitting.")
|
|
33
32
|
return undefined
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async get(url : string, params : Record<string, string | number | boolean> = {}) {
|
|
37
|
+
const buffer = await this.get_buffer(url, params)
|
|
38
|
+
if (buffer === undefined) {
|
|
39
|
+
return undefined
|
|
40
|
+
}
|
|
41
|
+
return this.text_decoder.decode(buffer)
|
|
34
42
|
}
|
|
35
43
|
|
|
36
44
|
async google_search(query : string, news : boolean = false) : Promise<Record<string, any>[] | undefined> {
|