Skip to content

Instantly share code, notes, and snippets.

@davidsan
Created March 25, 2020 20:57
Show Gist options
  • Save davidsan/ee9f587d9c552dcc32c2bb155c369083 to your computer and use it in GitHub Desktop.
Save davidsan/ee9f587d9c552dcc32c2bb155c369083 to your computer and use it in GitHub Desktop.
from bs4 import BeautifulSoup
import requests
import urllib
import re
query = "apple juice"
q = re.sub(" ", "+", query)
url = 'https://www.google.com/search?q='+q+'&tbm=isch&gbv=1'
header = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Firefox/68.0",
}
soup = BeautifulSoup(urllib.request.urlopen(urllib.request.Request(url, headers=header)), 'html.parser')
for img in soup.find_all("img", {"style": "border:1px solid #ccc;padding:1px"}):
print(img["src"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment