-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
41 lines (36 loc) · 1.06 KB
/
example.py
File metadata and controls
41 lines (36 loc) · 1.06 KB
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
// Import the Crawling API
const { CrawlingAPI } = require('crawlbase');
// Import fs module
const fs = require('fs');
// Set your Crawlbase token
const api = new CrawlingAPI({ token: 'YOUR_CRAWLBASE_JS_TOKEN' });
// URL of the Facebook page to scrape
const facebookPageURL = 'https://www.facebook.com/Alibaba.comGlobal/';
// options for Crawling API
const options = {
format: 'json',
ajax_wait: true,
scroll: true,
scroll_interval: 30,
};
// Get request to crawl the URL
api
.get(facebookPageURL, options)
.then((response) => {
if (response.statusCode === 200) {
// Parse the JSON response
const responseBody = JSON.parse(response.body);
const htmlContent = responseBody.body;
// Write the HTML content to an HTML file
fs.writeFile('output.html', htmlContent, (err) => {
if (err) {
console.error('Error writing to file:', err);
} else {
console.log('HTML content saved to output.html');
}
});
}
})
.catch((error) => {
console.error('API request error:', error);
});