deno deploy serverless服务爬虫
说明
随着deno deploy
相关serverless
服务的成熟及周边生态环境完善,爬虫也应该进入serverless新时代!
serverless服务爬虫
astral
astral是一个类似puppeteer
/playwright
deno
的浏览器驱动爬虫库。
-
github地址: https://github.com/lino-levan/astral
-
文档地址: https://astral.deno.dev/
browserless
browserless 是一个远程浏览 器驱动服务,通过网络远程链接操作该服务提供的浏览器
- browserless: https://www.browserless.io/
下面是browserless的一个官网demo,点开上面browserless网址即可提验,这里browserWSEndpoint
就是配置的远程服务网址
import puppeteer from "puppeteer";
// Try changing this! 👇
const URL = "https://pptr.dev/";
const main = async () => {
const browser = await puppeteer.connect({
browserWSEndpoint: `wss://chrome.browserless.io`,
});
const page = await browser.newPage();
await page.goto(URL);
return page.screenshot();
}
布署及测试
// Import Astral
import { launch } from "https://deno.land/x/astral@0.3.0/mod.ts";
// Connect to remote endpoint
const browser = await launch({
wsEndpoint: "wss://remote-browser-endpoint.example.com",
});
// Do stuff
const page = await browser.newPage("http://example.com");
console.log(await page.evaluate(() => document.title));
// Close connection
await browser.close();