#๐Ÿ”’ rate this guys

55 messages ยท Page 1 of 1 (latest)

ashen dragon
#

``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)`

buoyant hamletBOT
#

@ashen dragon

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

whole stream
#

i think adding if __name__ == "__main__": to the end is considered to be good practice for executables in python

#

so ```py
if name == "main":
show_price(get_price(soup))

URL , name = get_image(soup)

store_image(URL , name)
show_image(name)```
ashen dragon
#

can you run the code on your IDE

ashen dragon
whole stream
#

what other users?

#

other apps who import yours as a module?

ashen dragon
whole stream
#

i know

#

thats why i suggsted adding this condition, that way it wont run the code when imported

ashen dragon
#

oh , i understood you now

#

did you get the idea of my code

whole stream
#

yeah

#

it parses a site and displays some stuff

ashen dragon
#

it parse an amazon site , it required the page URL of an item on amazon site then displays the price of the item and it image

#

it also stores the image on you desktop

whole stream
#

yep, great stuff ๐Ÿ‘

#

If you want it to look extra clean, you can use a formatter

junior quartz
#

@ashen dragon 0/10 because it violates the terms of Amazon

#

!rule tos

buoyant hamletBOT
#

5. Do not provide or request help on projects that may violate terms of service, or that may be deemed inappropriate, malicious, or illegal.

whole stream
#

Wait, does amazon actually disallow parsing

warped dew
#

If by parsing you mean scraping

#

Most commercial sites do.

#

It's an exception when they do not.

ashen dragon
#

it s a light scraping m not damaging the amazon server

warped dew
#

Typically megacorps like Amazon might have an API or similar.

whole stream
warped dew
#

@ashen dragon It doesn't matter, if it's against the ToS it's against the rules.

ashen dragon
#

TOS?

warped dew
#

terms of service

ashen dragon
#

ok

warped dew
#

the rules of the website. usually you can find them at the bottom of a website next to the legal and/or copyright information

ashen dragon
#

bro who cares i havent even read them

warped dew
#

Always important to check - if those sites detect bot-like activity from your IP they may ban your IP address.

#

Well it's a rule of this server so you should care if you want to be on the server.

whole stream
warped dew
#

They've got different stuff on that site to practice with.

junior quartz
ashen dragon
junior quartz
#

Data is valuable and scraping it without permission amounts to stealing.

#

That's why there's like a bazillion lawsuits that have been filed against OpenAI for the data they scraped

warped dew
#

At any rate we don't need to discuss the ethics or morality or whatever - the only important thing is that it is not permissible to ask for help or provide help with projects that violate ToS here.

warped dew
#

diss?

#

Oh you mean discussion?

ashen dragon
#

yup

warped dew
#

Ok. You can close the channel with !close

ashen dragon
#

!close

buoyant hamletBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.