gsearch-node
v0.0.8
Published
API for making google search requests with captcha support
Downloads
10
Maintainers
Readme
var deathByCaptcha = require("deathbycaptcha")
var dbc = new deathByCaptcha("username", "password")
var gsearch = require("gsearch-node")
var gs = new gsearch({solver: dbc})Initailization (with custom solver)
var captchaSolver = { solve: function (img, cb) { //doSomeCaptchaSolving if (err) { cb (null, { err: err, solution: null }) return } cb (null, { err: null, solution: "solved captcha as string" }) } }API methods
gs.get(searchString, cb)This is an async function which returns acbwith(nullVar, respObj).nullVaris a variable withnullvalue.respObjis an object with following structure :-respObj = { err: null, resp: {}, // a response object from request library. use respObj.resp.body to get the html. parsed: {} // parsed html using whacko lib (a fork of cheerio). // so you can apply css selectors directly. }gs.getSync(seachString)This is a sync function which returns 'respObj' as described above.
Note on callbacks
The format of callbacks for this API is not(err, resp)but is(nullVar, respObj)whereerris a property ofrespObj. This is because I have used deasync lib which throwserrif(err, resp)format is used for the callback which make the code to break. Error handling is more easier as we can useifsyntax instead oftry catch.
(function () {
// var deathByCaptcha = require("deathbycaptcha")
// var dbc = new deathByCaptcha("username", "password")
var gsearch = require("gsearch-node")
var gs = new gsearch({solver: {}}) // {solver: dbc} for using deathbycaptcha api
console.log("Sync version")
var searchPage = gs.getSync("Everyone shifting to nodejs?")
if (!searchPage.err) {
$ = searchPage.parsed
$("a").each(function (i, a) {
console.log($(a).attr("href"))
})
} else {
console.log(searchPage.err)
}
console.log("\nAsync version")
gs.get("Everyone shifting to nodejs?", function (nullVar, searchPage) {
if (!searchPage.err) {
$ = searchPage.parsed
$("a").each(function (i, a) {
console.log($(a).attr("href"))
})
} else {
console.log(searchPage.err)
}
})
})()