-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathscrapingant.app.mjs
92 lines (91 loc) · 2.48 KB
/
scrapingant.app.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { axios } from "@pipedream/platform";
import constants from "./common/constants.mjs";
export default {
type: "app",
app: "scrapingant",
propDefinitions: {
url: {
type: "string",
label: "URL",
description: "The URL to scrape",
},
browser: {
type: "boolean",
label: "Browser",
description: "Enables using a headless browser for scraping",
optional: true,
},
returnPageSource: {
type: "boolean",
label: "Return Page Source",
description: "Enables returning data returned by the server and unaltered by the browser. When true JS won't be rendered",
optional: true,
},
cookies: {
type: "string",
label: "Cookies",
description: "Cookies to pass with a scraping request to the target site, i.e.: `cookie_name1=cookie_value1;cookie_name2=cookie_value2`",
optional: true,
},
jsSnippet: {
type: "string",
label: "JS Snippet",
description: "Base64 encoded JS snippet to run once page being loaded in the ScrapingAnt browser",
optional: true,
},
proxyType: {
type: "string",
label: "Proxy Type",
description: "Specifies the proxy type to make the request from",
options: constants.PROXY_TYPES,
optional: true,
},
proxyCountry: {
type: "string",
label: "Proxy Country",
description: "Specifies the proxy country to make the request from",
options: constants.PROXY_COUNTRIES,
optional: true,
},
waitForSelector: {
type: "string",
label: "Wait for Selector",
description: "The CSS selector of the element Scrapingant will wait for before returning the result",
optional: true,
},
blockResource: {
type: "string[]",
label: "Block Resource",
description: "Prevents cloud browser from loading specified resource types",
options: constants.RESOURCE_TYPES,
optional: true,
},
},
methods: {
_baseUrl() {
return "https://api.scrapingant.com/v2";
},
async _makeRequest(opts = {}) {
const {
$ = this,
path,
headers,
...otherOpts
} = opts;
return axios($, {
...otherOpts,
url: this._baseUrl() + path,
headers: {
...headers,
"x-api-key": `${this.$auth.api_token}`,
},
});
},
async generalExtraction(args = {}) {
return this._makeRequest({
path: "/general",
...args,
});
},
},
};