Skip to content

Commit 20fef2e

Browse files
committed
Initial AI-generated code
1 parent a72fc41 commit 20fef2e

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import spider from "../../spider.app.mjs";
2+
3+
export default {
4+
key: "spider-scrape-new-page",
5+
name: "Scrape New Page",
6+
description: "Initiates a new page scrape. [See the documentation](https://spider.cloud/docs/api)",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
spider,
11+
url: {
12+
propDefinition: [
13+
spider,
14+
"url",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const content = await this.spider.initiateCrawl();
20+
$.export("$summary", `Successfully scraped content from ${this.url}`);
21+
return content;
22+
},
23+
};

components/spider/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}

components/spider/spider.app.mjs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,50 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "spider",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
url: {
8+
type: "string",
9+
label: "URL to Scrape",
10+
description: "The URL of the page to scrape.",
11+
},
12+
},
513
methods: {
614
// this.$auth contains connected account data
715
authKeys() {
816
console.log(Object.keys(this.$auth));
917
},
18+
_baseUrl() {
19+
return "https://api.spider.cloud";
20+
},
21+
async _makeRequest(opts = {}) {
22+
const {
23+
$ = this, method = "GET", path = "/", headers, ...otherOpts
24+
} = opts;
25+
return axios($, {
26+
...otherOpts,
27+
method,
28+
url: this._baseUrl() + path,
29+
headers: {
30+
...headers,
31+
"Authorization": `Bearer ${this.$auth.api_key}`,
32+
"Content-Type": "application/json",
33+
},
34+
});
35+
},
36+
async initiateCrawl() {
37+
const response = await this._makeRequest({
38+
method: "POST",
39+
path: "/crawl",
40+
data: {
41+
url: this.url,
42+
},
43+
});
44+
if (Array.isArray(response) && response.length > 0) {
45+
return response[0].content;
46+
}
47+
throw new Error("No content returned from crawl");
48+
},
1049
},
11-
};
50+
};

0 commit comments

Comments
 (0)