-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New Components - bright_data #17907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New Components - bright_data #17907
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
components/bright_data/actions/scrape-serp/scrape-serp.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import brightData from "../../bright_data.app.mjs"; | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
|
||
export default { | ||
key: "bright_data-scrape-serp", | ||
name: "Scrape SERP", | ||
description: "Extract search engine results using Bright Data SERP API. [See the documentation](https://docs.brightdata.com/api-reference/rest-api/serp/scrape-serp)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
brightData, | ||
url: { | ||
propDefinition: [ | ||
brightData, | ||
"url", | ||
], | ||
description: "Complete target URL to scrape. Must include protocol (http/https), be publicly accessible. Example: `https://www.google.com/search?q=pizza`", | ||
}, | ||
zone: { | ||
propDefinition: [ | ||
brightData, | ||
"zone", | ||
() => ({ | ||
type: "serp", | ||
}), | ||
], | ||
}, | ||
format: { | ||
propDefinition: [ | ||
brightData, | ||
"format", | ||
], | ||
}, | ||
method: { | ||
propDefinition: [ | ||
brightData, | ||
"method", | ||
], | ||
}, | ||
country: { | ||
propDefinition: [ | ||
brightData, | ||
"country", | ||
], | ||
}, | ||
dataFormat: { | ||
propDefinition: [ | ||
brightData, | ||
"dataFormat", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const data = await this.brightData.requestWebsite({ | ||
$, | ||
data: { | ||
url: this.url, | ||
zone: this.zone, | ||
format: this.format, | ||
method: this.method, | ||
country: this.country, | ||
data_format: this.dataFormat, | ||
}, | ||
}); | ||
|
||
if (data.status_code === 400) { | ||
throw new ConfigurationError(data.body); | ||
} | ||
|
||
$.export("$summary", `Scraped SERP for ${this.url}`); | ||
return data; | ||
}, | ||
}; |
49 changes: 49 additions & 0 deletions
49
components/bright_data/actions/scrape-website/scrape-website.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import brightData from "../../bright_data.app.mjs"; | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
|
||
export default { | ||
key: "bright_data-scrape-website", | ||
name: "Scrape Website", | ||
description: "Scrape a website and return the HTML. [See the documentation](https://docs.brightdata.com/api-reference/web-scraper-api/synchronous-requests)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
brightData, | ||
datasetId: { | ||
propDefinition: [ | ||
brightData, | ||
"datasetId", | ||
], | ||
}, | ||
url: { | ||
propDefinition: [ | ||
brightData, | ||
"url", | ||
], | ||
description: "The URL of the website to scrape", | ||
}, | ||
}, | ||
async run({ $ }) { | ||
try { | ||
const data = await this.brightData.scrapeWebsite({ | ||
$, | ||
params: { | ||
dataset_id: this.datasetId, | ||
}, | ||
data: { | ||
input: [ | ||
{ | ||
url: this.url, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
$.export("$summary", `Scraped website ${this.url}`); | ||
return data; | ||
} catch (error) { | ||
const errors = (JSON.parse(error.message)).errors; | ||
throw new ConfigurationError(errors.map((e) => e.join(" - ")).join(" | ")); | ||
} | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}; |
67 changes: 67 additions & 0 deletions
67
components/bright_data/actions/unlock-website/unlock-website.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import brightData from "../../bright_data.app.mjs"; | ||
|
||
export default { | ||
key: "bright_data-unlock-website", | ||
name: "Unlock Website", | ||
description: "Send an API call to a URL and get the HTML back. Enables you to bypass anti-bot measures, manages proxies, and solves CAPTCHAs automatically for easier web data collection. [See the documentation](https://docs.brightdata.com/api-reference/rest-api/unlocker/unlock-website)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
brightData, | ||
url: { | ||
propDefinition: [ | ||
brightData, | ||
"url", | ||
], | ||
}, | ||
zone: { | ||
propDefinition: [ | ||
brightData, | ||
"zone", | ||
() => ({ | ||
type: "unblocker", | ||
}), | ||
], | ||
}, | ||
format: { | ||
propDefinition: [ | ||
brightData, | ||
"format", | ||
], | ||
}, | ||
method: { | ||
propDefinition: [ | ||
brightData, | ||
"method", | ||
], | ||
}, | ||
country: { | ||
propDefinition: [ | ||
brightData, | ||
"country", | ||
], | ||
}, | ||
dataFormat: { | ||
propDefinition: [ | ||
brightData, | ||
"dataFormat", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const data = await this.brightData.requestWebsite({ | ||
$, | ||
data: { | ||
url: this.url, | ||
zone: this.zone, | ||
format: this.format, | ||
method: this.method, | ||
country: this.country, | ||
data_format: this.dataFormat, | ||
}, | ||
}); | ||
|
||
$.export("$summary", `Unlocked website ${this.url}`); | ||
return data; | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,111 @@ | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
type: "app", | ||
app: "bright_data", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
datasetId: { | ||
type: "string", | ||
label: "Dataset ID", | ||
description: "The ID of the dataset to use", | ||
async options() { | ||
const datasets = await this.listDatasets(); | ||
return datasets.map((dataset) => ({ | ||
label: dataset.name, | ||
value: dataset.id, | ||
})); | ||
}, | ||
}, | ||
zone: { | ||
type: "string", | ||
label: "Zone", | ||
description: "Zone identifier that defines your Bright Data product configuration. Each zone contains targeting rules, output preferences, and access permissions. Manage zones at: https://brightdata.com/cp/zones", | ||
async options({ type }) { | ||
const zones = await this.listZones(); | ||
return zones?.filter((zone) => zone.type === type)?.map(({ name }) => name) || []; | ||
}, | ||
}, | ||
url: { | ||
type: "string", | ||
label: "URL", | ||
description: "Complete target URL to scrape. Must include protocol (http/https), be publicly accessible.", | ||
}, | ||
format: { | ||
type: "string", | ||
label: "Format", | ||
description: "Output format of the response", | ||
options: [ | ||
"json", | ||
"raw", | ||
], | ||
}, | ||
method: { | ||
type: "string", | ||
label: "Method", | ||
description: "HTTP method to use for the request", | ||
options: [ | ||
"GET", | ||
"POST", | ||
], | ||
optional: true, | ||
}, | ||
country: { | ||
type: "string", | ||
label: "Country", | ||
description: "Two-letter ISO 3166-1 country code for proxy location", | ||
optional: true, | ||
}, | ||
dataFormat: { | ||
type: "string", | ||
label: "Data Format", | ||
description: "Additional response format transformation: `markdown` converts HTML content to clean markdown format, `screenshot` captures a PNG image of the rendered page.", | ||
options: [ | ||
"markdown", | ||
"screenshot", | ||
], | ||
optional: true, | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_baseUrl() { | ||
return "https://api.brightdata.com"; | ||
}, | ||
_makeRequest({ | ||
$ = this, path, ...opts | ||
}) { | ||
return axios($, { | ||
url: `${this._baseUrl()}${path}`, | ||
headers: { | ||
Authorization: `Bearer ${this.$auth.api_key}`, | ||
}, | ||
...opts, | ||
}); | ||
}, | ||
listDatasets(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/datasets/list", | ||
...opts, | ||
}); | ||
}, | ||
listZones(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/zone/get_active_zones", | ||
...opts, | ||
}); | ||
}, | ||
scrapeWebsite(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/datasets/v3/scrape", | ||
method: "POST", | ||
...opts, | ||
}); | ||
}, | ||
requestWebsite(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/request", | ||
method: "POST", | ||
...opts, | ||
}); | ||
}, | ||
}, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.