I'm working on a python script that imports beautiful soup, requests, and urllib.request APIs to fetch images from the address https://www.example.com/image.jpg and it works OK, listing them in my documents folder well numbered.
I have tried varies methods listed here but none seem to have helped, on google the solution were revolving around getting tags.
The question is how to script it to fetch images from my example.html sitting on my C:/ drive using the mentioned python script, where the browser am using is Opera and the HTML URL is file:///C:/Users/folder/folder/Desktop/folder/example.html, on the web address bar.
Here is the python script,
from bs4 import BeautifulSoup
import urllib.request
import requests
# setting URL destination
url = "file:///C:/Users/folder/folder/Desktop/folder/example.html"
# retrieving HTML payload from the website
response = requests.get(url)
# using BeautifulSoup to parse the response object
soup = BeautifulSoup(response.content, "html.parser")
# finding Post images in the soup
images = soup.find_all("png", attrs={"alt":"Post image"})
# downloading images
number = 0
for image in images:
print(image["src"])
image_src = image["src"]
urllib.request.urlretrieve(image_src, str(number))
number += 1