2017-03-16 109 views
0

網址我使用的這個片段,使谷歌的搜索開始給定的名稱:錯誤而返回從節點JS

var parseXlsx = require('excel'); 
var scraper = require('google-search-scraper'); 

parseXlsx('foo.xlsx', function(err, data) { 
    if(err) throw err; 
    // data is an array of arrays 
    for(var i=1; i<5; i++){ 
     var stringToSearch = data[i][0]; 
     var options = { 
      query: stringToSearch, 
      limit: 1 
     }; 
     scraper.search(options, function(err, url) { 
      // This is called for each result 
      if(err) throw err; 
      console.log(url) 
     }); 
    } 
}); 

foo.xlsx文件,我有此列:

name1 
name2 
name3 
.... 

我」總是出現這個錯誤,我不知道爲什麼:

Error: Captcha 
    at Request._callback (C:\Users\user\node_modules\google-search-scraper\index.js:68:23) 
    at Request.self.callback (C:\Users\user\node_modules\google-search-scraper\node_modules\request\request.js:122:22) 
    at emitTwo (events.js:106:13) 
    at Request.emit (events.js:191:7) 
    at Request.<anonymous> (C:\Users\user\node_modules\google-search-scraper\node_modules\request\request.js:888:14) 
    at emitOne (events.js:101:20) 
    at Request.emit (events.js:188:7) 
    at IncomingMessage.<anonymous> (C:\Users\user\node_modules\google-search-scraper\node_modules\request\request.js:839:12) 
    at emitNone (events.js:91:20) 
    at IncomingMessage.emit (events.js:185:7) 

在此先感謝。

+0

作品我node.js的7.0.0,谷歌搜索刮刀:0.0.3,擅長:0.1.7。也許你只需要更新它們。 – pergy

+0

我有節點js 7.0.0 – OiRc

回答

1

錯誤聽起來像不能通過一個RECAPCHA。

Error:Capcha

您是否嘗試過使用deathbycaptcha - NPM包來解決?

https://www.npmjs.com/package/deathbycaptcha

var scraper = require('google-search-scraper'); 
var DeathByCaptcha = require('deathbycaptcha'); 

var dbc = new DeathByCaptcha('username', 'password'); 

var options = { 
    query: 'site:edu "information theory"', 
    age: 'y', // less than a year, 
    solver: dbc 
}; 

scraper.search(options, function(err, url) { 
    // This is called for each result 
    if(err) throw err; 
    console.log(url) 
}); 
+0

你可以用我的代碼做一個例子嗎? – OiRc

+0

我可以得到用戶名和密碼? – OiRc

+0

創建一個帳戶http://www.deathbycaptcha.com/user/login –