瀏覽代碼

proxy support

kpmy 7 年之前
父節點
當前提交
1a54930c7b
共有 1 個文件被更改,包括 8 次插入3 次删除
  1. 8 3
      src/crawler.js

+ 8 - 3
src/crawler.js

@@ -87,12 +87,17 @@ function doCrawl(cat, force) {
                 let nextUrl = getUrlDay(date.toDate(), cat, page);
                 let nextUrl = getUrlDay(date.toDate(), cat, page);
                 console.log(nextUrl);
                 console.log(nextUrl);
                 let ret = [];
                 let ret = [];
-                request({
+                let params = {
                     uri: nextUrl,
                     uri: nextUrl,
                     transform: function (body) {
                     transform: function (body) {
                         return cheerio.load(body);
                         return cheerio.load(body);
                     }
                     }
-                }).then(function ($) {
+                };
+
+                let proxy = settings().get('proxy');
+                if(proxy && proxy.active) params.proxy = `http://${proxy.host}:${proxy.port}`;
+
+                request(params).then(function ($) {
                     extractRows(r => {
                     extractRows(r => {
                         r.date = parseInt(date.clone().startOf('day').format('x'));
                         r.date = parseInt(date.clone().startOf('day').format('x'));
                         r.category = cat;
                         r.category = cat;
@@ -163,7 +168,7 @@ function doAllCrawl() {
         }, function (e) {
         }, function (e) {
             crawling = false;
             crawling = false;
             console.error(e);
             console.error(e);
-            throw e;
+            //throw e;
         })
         })
     }
     }