A Google Images scraper without using Google CSE.
npm install google-imgsA simple google images scraper without using google cse. For downloading images you can use http/https api or other npm libs. like request etc.
npm i google-imgs
`Require to export function
`js
//CommonJS
const google = require("google-imgs");
`SIMPLE USAGE
$3
`js
const google = require("google-imgs");//searchImage param. is string
let result = await google.searchImage()
console.log(result)
`$3
METHOD 1: Promise.all()
`js
const google = require("google-imgs");//searchImage param. is string
let result = await google.searchImage()
//first method using promise all
let workingUrls = [], i = 0;
await Promise.all(result.map(async url =>{
await axios.get(url).then(r=>{
if (r.status === 200){
workingUrls.push({imgUrl: url})
}
}).catch(e=>{})
i++
}))
//filtered, all urls are surely working
console.log(workingUrls)
`METHOD 2: limiting working urls (faster)
`js
const google = require("google-imgs");//searchImage param. is string
let result = await google.searchImage()
//2nd method limiting the working urls - in this example if workingUrls length reach 6 it will stop loop and logs the 6 working urls
let workingUrls = [], i = 0;
while (workingUrls.length < 6) {
await axios.get(urls).then(r=>{
if (r.status === 200){
workingUrls.push({imgUrl: urls})
}
}).catch(e=>{})
i++
}
//filtered, all urls are surely working
console.log(workingUrls)
``