{"id":14979,"date":"2024-12-08T23:06:05","date_gmt":"2024-12-08T15:06:05","guid":{"rendered":"https:\/\/www.aisharenet.com\/?p=14979"},"modified":"2024-12-08T23:06:05","modified_gmt":"2024-12-08T15:06:05","slug":"crawlee","status":"publish","type":"post","link":"https:\/\/www.kdjingpai.com\/en\/crawlee\/","title":{"rendered":"Crawlee\uff1a\u4f7f\u7528Node.js\u6784\u5efa\u53ef\u9760\u7684\u7f51\u7edc\u722c\u866b\u548c\u6d4f\u89c8\u5668\u81ea\u52a8\u5316\u5de5\u5177"},"content":{"rendered":"<p>Crawlee \u662f\u4e00\u4e2a\u7531 Apify \u5f00\u53d1\u7684\u5f00\u6e90\u7f51\u7edc\u722c\u866b\u548c\u6d4f\u89c8\u5668\u81ea\u52a8\u5316\u5e93\uff0c\u4e13\u4e3a Node.js \u73af\u5883\u8bbe\u8ba1\u3002\u5b83\u652f\u6301 JavaScript \u548c TypeScript\uff0c\u80fd\u591f\u4e0e Puppeteer\u3001Playwright\u3001Cheerio\u3001JSDOM \u7b49\u5de5\u5177\u914d\u5408\u4f7f\u7528\uff0c\u63d0\u4f9b\u5f3a\u5927\u7684\u6570\u636e\u6293\u53d6\u548c\u81ea\u52a8\u5316\u529f\u80fd\u3002Crawlee \u5141\u8bb8\u7528\u6237\u6784\u5efa\u53ef\u9760\u7684\u722c\u866b\uff0c\u63d0\u53d6 AI\u3001LLM\u3001RAG \u6216 GPTs \u6240\u9700\u7684\u6570\u636e\uff0c\u5e76\u4e0b\u8f7d HTML\u3001PDF\u3001JPG\u3001PNG \u7b49\u6587\u4ef6\u3002\u5176\u8bbe\u8ba1\u65e8\u5728\u4f7f\u722c\u866b\u770b\u8d77\u6765\u66f4\u50cf\u4eba\u7c7b\u64cd\u4f5c\uff0c\u80fd\u591f\u89c4\u907f\u73b0\u4ee3\u53cd\u722c\u866b\u673a\u5236\uff0c\u652f\u6301\u4ee3\u7406\u8f6e\u6362\u548c\u4f1a\u8bdd\u7ba1\u7406\uff0c\u9002\u7528\u4e8e\u5404\u79cd\u590d\u6742\u7684\u7f51\u7edc\u6293\u53d6\u4efb\u52a1\u3002<\/p>\n<blockquote><p>Crawlee for Python \u5411\u65e9\u671f\u91c7\u7528\u8005\u5f00\u653e\uff01<\/p><\/blockquote>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter  wp-image-14980\" title=\"Crawlee\uff1a\u4f7f\u7528Node.js\u6784\u5efa\u53ef\u9760\u7684\u7f51\u7edc\u722c\u866b\u548c\u6d4f\u89c8\u5668\u81ea\u52a8\u5316\u5de5\u5177-1\" src=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/9194df622d40de3.jpg\" alt=\"Crawlee\uff1a\u4f7f\u7528Node.js\u6784\u5efa\u53ef\u9760\u7684\u7f51\u7edc\u722c\u866b\u548c\u6d4f\u89c8\u5668\u81ea\u52a8\u5316\u5de5\u5177-1\" width=\"1053\" height=\"543\" srcset=\"https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/9194df622d40de3.jpg 1344w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/9194df622d40de3-300x155.jpg 300w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/9194df622d40de3-1024x528.jpg 1024w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/9194df622d40de3-768x396.jpg 768w, https:\/\/www.kdjingpai.com\/wp-content\/uploads\/2024\/12\/9194df622d40de3-18x9.jpg 18w\" sizes=\"auto, (max-width: 1053px) 100vw, 1053px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>\u529f\u80fd\u5217\u8868<\/h2>\n<ul>\n<li>HTTP \u548c\u65e0\u5934\u6d4f\u89c8\u5668\u722c\u53d6\u7684\u5355\u4e00\u63a5\u53e3<\/li>\n<li>\u6301\u4e45\u5316\u7684 URL \u722c\u53d6\u961f\u5217\uff08\u5e7f\u5ea6\u4f18\u5148\u548c\u6df1\u5ea6\u4f18\u5148\uff09<\/li>\n<li>\u53ef\u63d2\u62d4\u7684\u6570\u636e\u548c\u6587\u4ef6\u5b58\u50a8<\/li>\n<li>\u81ea\u52a8\u6839\u636e\u7cfb\u7edf\u8d44\u6e90\u8fdb\u884c\u6269\u5c55<\/li>\n<li>\u96c6\u6210\u4ee3\u7406\u8f6e\u6362\u548c\u4f1a\u8bdd\u7ba1\u7406<\/li>\n<li>\u751f\u547d\u5468\u671f\u53ef\u901a\u8fc7\u94a9\u5b50\u81ea\u5b9a\u4e49<\/li>\n<li>CLI \u5de5\u5177\u7528\u4e8e\u5f15\u5bfc\u9879\u76ee<\/li>\n<li>\u53ef\u914d\u7f6e\u7684\u8def\u7531\u3001\u9519\u8bef\u5904\u7406\u548c\u91cd\u8bd5\u673a\u5236<\/li>\n<li>\u63d0\u4f9b Dockerfiles \u4ee5\u4fbf\u90e8\u7f72<\/li>\n<li>\u4f7f\u7528 TypeScript \u7f16\u5199\uff0c\u652f\u6301\u6cdb\u578b<\/li>\n<li>\u652f\u6301 HTTP2 \u548c\u81ea\u52a8\u751f\u6210\u6d4f\u89c8\u5668\u6837\u5f0f\u7684\u8bf7\u6c42\u5934<\/li>\n<li>\u96c6\u6210\u5feb\u901f HTML \u89e3\u6790\u5668\uff08Cheerio \u548c JSDOM\uff09<\/li>\n<li>\u652f\u6301 JSON API \u6293\u53d6<\/li>\n<li>\u652f\u6301 JavaScript \u6e32\u67d3\u548c\u622a\u56fe<\/li>\n<li>\u65e0\u5934\u548c\u6709\u5934\u6a21\u5f0f\u652f\u6301<\/li>\n<li>\u81ea\u52a8\u751f\u6210\u4eba\u7c7b\u6837\u5f0f\u7684\u6307\u7eb9<\/li>\n<li>\u4f7f\u7528 Playwright \u548c Puppeteer \u7684\u7edf\u4e00\u63a5\u53e3<\/li>\n<li>\u652f\u6301 Chrome\u3001Firefox\u3001Webkit \u7b49\u6d4f\u89c8\u5668<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>\u4f7f\u7528\u5e2e\u52a9<\/h2>\n<h3>\u5b89\u88c5<\/h3>\n<p>Crawlee \u9700\u8981 Node.js 16 \u6216\u66f4\u9ad8\u7248\u672c\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5feb\u901f\u5b89\u88c5\u5e76\u521b\u5efa\u4e00\u4e2a\u793a\u4f8b\u722c\u866b\uff1a<\/p>\n<pre><code>npx crawlee create my-crawler\r\ncd my-crawler\r\nnpm start\r\n<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u66f4\u559c\u6b22\u624b\u52a8\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>npm install crawlee playwright\r\n<\/code><\/pre>\n<p>\u7136\u540e\u5728\u4f60\u7684\u9879\u76ee\u4e2d\u5bfc\u5165\u5e76\u4f7f\u7528\uff1a<\/p>\n<pre><code>import { PlaywrightCrawler, Dataset } from 'crawlee';\r\nconst crawler = new PlaywrightCrawler({\r\nasync requestHandler({ request, page, enqueueLinks, log }) {\r\nconst title = await page.title();\r\nlog.info(`Title of ${request.loadedUrl} is '${title}'`);\r\nawait Dataset.pushData({ title, url: request.loadedUrl });\r\nawait enqueueLinks();\r\n},\r\n\/\/ headless: false, \/\/ Uncomment to see the browser window\r\n});\r\nawait crawler.run(['https:\/\/crawlee.dev']);\r\n<\/code><\/pre>\n<h3>\u529f\u80fd\u64cd\u4f5c\u6d41\u7a0b<\/h3>\n<ol>\n<li><strong>\u521b\u5efa\u722c\u866b\u9879\u76ee<\/strong>\uff1a\u4f7f\u7528 Crawlee CLI \u5feb\u901f\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u722c\u866b\u9879\u76ee\uff0cCLI \u4f1a\u5b89\u88c5\u6240\u6709\u5fc5\u8981\u7684\u4f9d\u8d56\u5e76\u6dfb\u52a0\u6837\u677f\u4ee3\u7801\u3002<\/li>\n<li><strong>\u914d\u7f6e\u722c\u866b<\/strong>\uff1a\u5728\u9879\u76ee\u4e2d\u914d\u7f6e\u722c\u866b\u7684\u8bf7\u6c42\u5904\u7406\u903b\u8f91\u3001\u6570\u636e\u5b58\u50a8\u4f4d\u7f6e\u3001\u4ee3\u7406\u8bbe\u7f6e\u7b49\u3002<\/li>\n<li><strong>\u8fd0\u884c\u722c\u866b<\/strong>\uff1a\u901a\u8fc7\u547d\u4ee4\u884c\u8fd0\u884c\u722c\u866b\uff0cCrawlee \u4f1a\u81ea\u52a8\u5904\u7406\u8bf7\u6c42\u3001\u6293\u53d6\u6570\u636e\u5e76\u5b58\u50a8\u7ed3\u679c\u3002<\/li>\n<li><strong>\u6570\u636e\u5b58\u50a8<\/strong>\uff1aCrawlee \u9ed8\u8ba4\u5c06\u6570\u636e\u5b58\u50a8\u5728\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u7684\u00a0<code>.\/storage<\/code>\u00a0\u6587\u4ef6\u5939\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u8986\u76d6\u6b64\u76ee\u5f55\u3002<\/li>\n<li><strong>\u6269\u5c55\u529f\u80fd<\/strong>\uff1a\u6839\u636e\u9700\u8981\u6dfb\u52a0\u81ea\u5b9a\u4e49\u94a9\u5b50\u3001\u9519\u8bef\u5904\u7406\u673a\u5236\u548c\u91cd\u8bd5\u7b56\u7565\uff0c\u786e\u4fdd\u722c\u866b\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002<\/li>\n<\/ol>\n<h3>\u4ee3\u7406\u548c\u4f1a\u8bdd\u7ba1\u7406<\/h3>\n<p>Crawlee \u96c6\u6210\u4e86\u4ee3\u7406\u8f6e\u6362\u548c\u4f1a\u8bdd\u7ba1\u7406\u529f\u80fd\uff0c\u786e\u4fdd\u722c\u866b\u5728\u6293\u53d6\u8fc7\u7a0b\u4e2d\u4e0d\u4f1a\u88ab\u76ee\u6807\u7f51\u7ad9\u5c4f\u853d\u3002\u53ef\u4ee5\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u8bbe\u7f6e\u4ee3\u7406\u5217\u8868\u548c\u4f1a\u8bdd\u53c2\u6570\uff0c\u5b9e\u73b0\u81ea\u52a8\u8f6e\u6362\u548c\u7ba1\u7406\u3002<\/p>\n<h3>\u90e8\u7f72<\/h3>\n<p>Crawlee \u63d0\u4f9b\u4e86 Dockerfiles\uff0c\u65b9\u4fbf\u5c06\u722c\u866b\u90e8\u7f72\u5230\u4e91\u7aef\u6216\u5176\u4ed6\u73af\u5883\u4e2d\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6784\u5efa\u548c\u8fd0\u884c Docker \u5bb9\u5668\uff1a<\/p>\n<pre><code>docker build -t my-crawler .\r\ndocker run my-crawler<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Crawlee \u662f\u4e00\u4e2a\u7531 Apify \u5f00\u53d1\u7684\u5f00\u6e90\u7f51\u7edc\u722c\u866b\u548c\u6d4f\u89c8\u5668\u81ea\u52a8\u5316\u5e93\uff0c\u4e13\u4e3a Node.js \u73af\u5883\u8bbe\u8ba1\u3002\u5b83\u652f\u6301 JavaScript \u548c TypeScript\uff0c\u80fd\u591f\u4e0e Puppeteer\u3001Playwright\u3001Cheerio\u3001JSDOM &#8230;<\/p>\n","protected":false},"author":1,"featured_media":61378,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[230],"class_list":["post-14979","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tool","tag-aikaiyuanxiangmu"],"_links":{"self":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts\/14979","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/comments?post=14979"}],"version-history":[{"count":0,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/posts\/14979\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/media\/61378"}],"wp:attachment":[{"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/media?parent=14979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/categories?post=14979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kdjingpai.com\/en\/wp-json\/wp\/v2\/tags?post=14979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}