Skip to content

Commit b8e0715

Browse files
committed
wip
1 parent ffbdc51 commit b8e0715

File tree

7 files changed

+179
-9
lines changed

7 files changed

+179
-9
lines changed

components/oxylabs/actions/create-proxy-session/create-proxy-session.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "oxylabs-create-proxy-session",
66
name: "Create Proxy Session",
77
description: "Establish a proxy session using the Residential Proxy endpoint. [See the documentation](https://developers.oxylabs.io/proxies/residential-proxies/session-control#establishing-session)",
8-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
99
type: "action",
1010
props: {
1111
oxylabs,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import oxylabs from "../../oxylabs.app.mjs";
2+
import { parseObject } from "../../common/utils.mjs";
3+
4+
export default {
5+
key: "oxylabs-create-schedule",
6+
name: "Create Schedule",
7+
description: "Create a schedule for a scraping job. [See the documentation](https://developers.oxylabs.io/scraping-solutions/web-scraper-api/features/scheduler#create-a-new-schedule)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
oxylabs,
12+
chron: {
13+
type: "string",
14+
label: "Cron Expression",
15+
description: "Cron schedule expression. It determines how often the submitted schedule will run. E.g. `0 3 * * 1`. Read more [here](https://crontab.guru/) and [here](https://docs.oracle.com/cd/E12058_01/doc/doc.1014/e12030/cron_expressions.htm).",
16+
},
17+
items: {
18+
type: "string[]",
19+
label: "Items",
20+
description: "List of Scraper APIs job parameter sets that should be executed as part of the schedule. E.g. `[{\"source\": \"universal\", \"url\": \"https://ip.oxylabs.io\"}]` [See the documentation](https://developers.oxylabs.io/scraping-solutions/web-scraper-api/features/scheduler#create-a-new-schedule) for more information.",
21+
propDefinition: [
22+
oxylabs,
23+
"items",
24+
],
25+
},
26+
endTime: {
27+
type: "string",
28+
label: "End Time",
29+
description: "The time at which the schedule should stop running. E.g. `2032-12-21 12:34:45`",
30+
},
31+
},
32+
async run({ $ }) {
33+
const response = await this.oxylabs.createSchedule({
34+
$,
35+
data: {
36+
cron: this.chron,
37+
items: parseObject(this.items),
38+
end_time: this.endTime,
39+
},
40+
});
41+
$.export("$summary", `Successfully created schedule: ${response.schedule_id}`);
42+
return response;
43+
},
44+
};

components/oxylabs/actions/scrape-url/scrape-url.mjs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
11
import oxylabs from "../../oxylabs.app.mjs";
2+
import constants from "../../common/constants.mjs";
23

34
export default {
45
key: "oxylabs-scrape-url",
56
name: "Scrape URL",
67
description: "Scrape a URL. [See the documentation](https://developers.oxylabs.io/scraping-solutions/web-scraper-api)",
7-
version: "0.0.{{ts}}",
8+
version: "0.0.1",
89
type: "action",
910
props: {
1011
oxylabs,
12+
source: {
13+
type: "string",
14+
label: "Source",
15+
description: "Sets the scraper that will be used to process your request",
16+
options: constants.URL_SOURCES,
17+
default: "universal",
18+
},
1119
url: {
1220
type: "string",
1321
label: "URL",
1422
description: "The URL to scrape",
1523
},
1624
geoLocation: {
17-
type: "string",
18-
label: "Geo Location",
19-
description: "The geo locatio to scrape from. E.g. `United States`",
20-
optional: true,
25+
propDefinition: [
26+
oxylabs,
27+
"geoLocation",
28+
],
2129
},
2230
},
2331
async run({ $ }) {
24-
const response = await this.oxylabs.scrapeUrl({
32+
const response = await this.oxylabs.scrape({
2533
$,
2634
data: {
2735
source: "universal",
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import oxylabs from "../../oxylabs.app.mjs";
2+
import constants from "../../common/constants.mjs";
3+
4+
export default {
5+
key: "oxylabs-scrape-with-query",
6+
name: "Scrape with Query",
7+
description: "Extract data using a search query. [See the documentation](https://developers.oxylabs.io/scraping-solutions/web-scraper-api)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
oxylabs,
12+
source: {
13+
type: "string",
14+
label: "Source",
15+
description: "Sets the scraper that will be used to process your request",
16+
options: constants.QUERY_SOURCES,
17+
},
18+
query: {
19+
type: "string",
20+
label: "Query",
21+
description: "The query to search for. [See the documentation](https://developers.oxylabs.io/scraping-solutions/web-scraper-api/targets) for more information about specific sources/targets",
22+
},
23+
geoLocation: {
24+
propDefinition: [
25+
oxylabs,
26+
"geoLocation",
27+
],
28+
},
29+
},
30+
async run({ $ }) {
31+
const response = await this.oxylabs.scrape({
32+
$,
33+
data: {
34+
source: this.source,
35+
query: this.query,
36+
geo_location: this.geoLocation,
37+
},
38+
});
39+
$.export("$summary", `Successfully scraped using query: ${this.query}`);
40+
return response;
41+
},
42+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const URL_SOURCES = [
2+
"universal",
3+
"amazon",
4+
"google",
5+
"bing",
6+
"kroger",
7+
];
8+
9+
const QUERY_SOURCES = [
10+
"amazon_product",
11+
"amazon_search",
12+
"amazon_pricing",
13+
"amazon_sellers",
14+
"amazon_bestsellers",
15+
"amazon_reviews",
16+
"amazon_questions",
17+
"google_search",
18+
"google_ads",
19+
"google_images",
20+
"google_lens",
21+
"google_maps",
22+
"google_travel_hotels",
23+
"google_suggest",
24+
"google_trends_explore",
25+
"google_shopping_product",
26+
"google_shopping_search",
27+
"google_shopping_pricing",
28+
"bing_search",
29+
"kroger_product",
30+
"kroger_search",
31+
"youtube_transcript",
32+
];
33+
34+
export default {
35+
URL_SOURCES,
36+
QUERY_SOURCES,
37+
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) {
3+
return undefined;
4+
}
5+
if (typeof obj === "string") {
6+
try {
7+
return JSON.parse(obj);
8+
} catch (e) {
9+
return obj;
10+
}
11+
}
12+
if (Array.isArray(obj)) {
13+
return obj.map(parseObject);
14+
}
15+
if (typeof obj === "object") {
16+
return Object.fromEntries(Object.entries(obj).map(([
17+
key,
18+
value,
19+
]) => [
20+
key,
21+
parseObject(value),
22+
]));
23+
}
24+
return obj;
25+
};

components/oxylabs/oxylabs.app.mjs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ import { HttpsProxyAgent } from "https-proxy-agent";
44
export default {
55
type: "app",
66
app: "oxylabs",
7-
propDefinitions: {},
7+
propDefinitions: {
8+
geoLocation: {
9+
type: "string",
10+
label: "Geo Location",
11+
description: "The geo locatio to scrape from. E.g. `United States`",
12+
optional: true,
13+
},
14+
},
815
methods: {
916
_getBaseUrl() {
1017
return `https://${this.$auth.api_name}.oxylabs.io/v1`;
@@ -24,7 +31,7 @@ export default {
2431
...opts,
2532
});
2633
},
27-
scrapeUrl(opts = {}) {
34+
scrape(opts = {}) {
2835
return this._makeRequest({
2936
method: "POST",
3037
path: "/queries",
@@ -41,5 +48,12 @@ export default {
4148
...opts,
4249
});
4350
},
51+
createSchedule(opts = {}) {
52+
return this._makeRequest({
53+
method: "POST",
54+
path: "/schedules",
55+
...opts,
56+
});
57+
},
4458
},
4559
};

0 commit comments

Comments
 (0)