christophebe / serp

Google Search SERP Scraper
101 stars 23 forks source link

all result urls are not found able or wrong here is my code #14

Closed Tomato6966 closed 3 years ago

Tomato6966 commented 3 years ago

const Discord = require("discord.js"); const serp = require("serp"); const request = require("request"); //CLIENT const client = new Discord.Client() const config = { "token": "your token in here", "prefix" : "!" } client.login(config.token); client.on("ready", () => console.log("BOT IS READY")) client.on("message", msg => { if(!msg.guild || msg.author.bot || !msg.content.startsWith(config.prefix)) return; const args = msg.content.slice(config.prefix.length).trim().split(/ +/g); const cmd = args.shift().toLowerCase(); if(cmd === "ping") return msg.reply(My Ping is: \${client.ws.ping}ms`); else if(cmd === "google") { if(!args[0]) return msg.reply(please add your search term: `${config.prefix}google Hello world``) var options = { host : "google.com", qs : { q : args.join(" "), }, num : 10, retry : 3, }; serp.search(options).then(links => {

console.log(links[0].url.replace("/url?esrc=s&q=&rct=j&sa=U&url=", ""))

  msg.reply(new Discord.MessageEmbed().setDescription(`${links.map((link, index) => `**${index}. **[${link.title}](${link.url.replace("/url?esrc=s&q=&rct=j&sa=U&url=", "")})`).join("\n")}`.substr(0, 2000))
  .setFooter("PICK YOUR RESULT!", msg.author.displayAvatarURL({dynamic:true}))).then(ms => {
    ms.channel.awaitMessages(m => m.author.id == msg.author.id, { time: 50000, max: 1, errors: ["time"] }).then(coll=>{
      if(Number(coll) > 10 || Number(coll) < 0) return msg.reply("NOT A VALID INPUT ERROR!")
      msg.reply(`**${links[coll.first().content].title}**\n\n${links[coll.first().content].url.replace("/url?esrc=s&q=&rct=j&sa=U&url=", "")}`.substr(0, 2000));
    }).catch(e=>{
      msg.reply("NOT ANSWERED IN TIME / INVALID INPUT");
    })
  })
})

} else return msg.reply(UNKNOWN CMD! These are all of my cmds: \n\``${config.prefix}ping | --> shows you my latency\n${config.prefix}google | --> googles smt````); })

christophebe commented 3 years ago

Sorry for the delay, I haven't used this module for a long time :-) I will update it in the upcoming days. Your problem is probably linked to the fact that Google now displays a cookie consent popup window.

Tomato6966 commented 3 years ago

its alright, i made my own scraper