Skip to content

Commit

Permalink
Merge pull request #110 from Ibrahimrahhal/master
Browse files Browse the repository at this point in the history
* Support more selectors

---------

Co-authored-by: Peter Evers <[email protected]>
  • Loading branch information
pevers authored Jan 22, 2024
2 parents 7c47d84 + ffa0498 commit 3e81f41
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/google/scraper.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,11 @@ class GoogleScraper {

$('#islrg div[jsaction][data-tbnid]').each(function (_i, containerElement) {
const containerElement_ = $(containerElement);
const linkElementHref = containerElement_.find("a[href^='/imgres']").attr('href');
if (linkElementHref) {
// linkElementHref could be undefined
const linkElementHrefExpectedSelectors = ["a[href^='/imgres']", "a[jsaction]"];
const linkElementHref = linkElementHrefExpectedSelectors
.map(s => containerElement_.find(s).attr('href'))
.find(e => e);
if (linkElementHref) { // linkElementHref could be undefined
const imageElementAlt = containerElement_.find('img').attr('alt');
const parsedLink = url.parse(linkElementHref, { parseQueryString: true });
const imageurl = parsedLink.query.imgurl;
Expand Down

0 comments on commit 3e81f41

Please sign in to comment.