# Fetch Image ```python import re import requests from bs4 import BeautifulSoup #keyword keyword = "水獺" # URL url = "https://www.google.com/search?q=" + keyword + "&safe=active&source=lnms&tbm=isch" # Get request response = requests.get(url) # Parsering Response soup = BeautifulSoup(response.text, "html.parser") # find out image file images = soup.find_all("img") # craete the list to save the image imageList = [] # regular expression pattern = "^https" for image in images: # get the image src imageURL = image.get("src") # Regular if re.match(pattern, imageURL): imageList.append(imageURL) print(imageList) # ------------------------------------------------------------- # Download the image imageNumber = 0 for url in imageList: response = requests.get(url) with open(f"{keyword} {imageNumber}.jpg","wb") as file: file.write(response.content) imageNumber += 1 ``` Result   Author: 侯智晟 Gmail: meowheckerouo@gmail.com
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.