thibauts / node-google-search-scraper

Google search scraper with captcha solving support
MIT License
89 stars 37 forks source link

limit not working #4

Closed Axecident closed 7 years ago

Axecident commented 8 years ago

I have tried the following piece of code

if(message.content.startsWith ("/google")) { var lastmsg = message var msgArray = message.content.split('/google ') var searchoptions = { query: msgArray[1], host: 'www.google.com.au', lang: 'en', limit: 1 }; var firstSearch = false; scraper.search(searchoptions, function(err, url) { //this is called for each result if(err) throw err; if(firstSearch == false) { console.log(url) message.channel.sendMessage(url).catch(console.error); firstSearch = true; } }); As you can see in that code i made a creative work-around.

But I shouldn't have had to do that, the problem is that even though i set limit to 1 it still didn't change it to 1.

I even thought maybe it's adding a zero on the end? making it 10 anyway? So i changed it to 01 but that didn't work either.

Is there something I'm doing wrong?

P.S. Ignore the if statement about message.content and anything else about messages. That's there because i am using this inside of a discord bot.

thibauts commented 8 years ago

Please post formatted code. It's really difficult to read as is. Thanks

Axecident commented 8 years ago

The code was formatted when I posted it. It was also inserted into the post via "Insert code".

The best I can do to make it more view-able is put it in a text file. limit_problem.txt.txt

thibauts commented 7 years ago

The best you can do is click on "Styling with Markdown ..." below the comment box and learn how to style comments on github.

If you don't bother to do that don't expect me to bother considering your issue.

ElDondo commented 7 years ago

I have had the same problem while coding my Discord bot.. it always returned 9 urls even though I had set my limit to 1. I was trying to fix it by making small changes in the node_modules/google-search-scraper/index.js and made it work by adding

newResults.length = 1;

to the file just before

newResults.forEach(function(result) {
      callback(null, result);
    });

And then it respected the limit I set in my Discord bot code. Don't ask me why this works though, I was just trying some things and apparently this worked :D