``py
import requests
from bs4 import BeautifulSoup
from PIL import Image
#get Amazon item page URL
URL = input("Enter the URL of the image page : ")
rq = requests.get(URL)
content = rq.text
soup = BeautifulSoup(content, "lxml")
scrape to the price of the item
def get_price(soup) :
symbol_tag = soup.find("span", {"class" : "a-price-symbol"})
symbol = symbol_tag.text
siblings = symbol_tag.find_next_siblings()
price = ""
for sibling in siblings :
price+=sibling.text
price+= symbol
return price
show the price of the item
def show_price(price) :
print("\n\n\n")
print("")
print()
print(f"the price is {price}")
print()
print("")
get item image
def get_image(soup) :
image_tag = soup.find("img" , {"id" : "landingImage" })
image_URL = image_tag["src"]
image_name = image_tag["alt"]
return image_URL , image_name
store the image
def store_image(URL , name) :
image = requests.get(URL).content
with open(f"{name}.jpg" , "wb") as f :
f.write(image)
show the image
def show_image(name) :
my_image = Image.open(f"{name}.jpg")
my_image.show()
show_price(get_price(soup))
URL , name = get_image(soup)
store_image(URL , name)
show_image(name)`