Last active
November 5, 2021 18:20
-
-
Save RayyanNafees/9f3e7d70a8634bdeb458b3496c2b18d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function getImages(query) { | |
| const url = `https://www.google.com/search?q=${query}&tbm=isch`; | |
| const html = await fetch(url).then((r) => r.text()); | |
| const parser = new DOMParser(); | |
| const doc = parser.parseFromString(html, "text/html"); | |
| const images = [...doc.getElementsByClassName("rg_i Q4LuWd")]; // all search results are of the class "rg_i Q4LuWd" | |
| const links = images.map((i) => i.src); | |
| return links; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment