Skip to content

Instantly share code, notes, and snippets.

@RayyanNafees
Last active November 5, 2021 18:20
Show Gist options
  • Select an option

  • Save RayyanNafees/9f3e7d70a8634bdeb458b3496c2b18d7 to your computer and use it in GitHub Desktop.

Select an option

Save RayyanNafees/9f3e7d70a8634bdeb458b3496c2b18d7 to your computer and use it in GitHub Desktop.
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