Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import io
- from bs4 import BeautifulSoup
- from PIL import Image
- from PIL.ImageDraw import ImageDraw
- from PIL.ImageFont import truetype
- BASE_URL = "https://mall.industry.siemens.com/mall/de/de/Catalog/Product/"
- PRODUCT = "3SU1050-0AA10-0AA0"
- UA = {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:92.0) Gecko/20100101 Firefox/92.0"}
- def get_picture(product):
- resp = requests.get(BASE_URL + product, headers=UA)
- bs = BeautifulSoup(resp.content, "lxml")
- img = bs.find("img", {"class": "productPicture"})
- if img:
- return product, img["src"]
- def show_img(url, product):
- fd = io.BytesIO(requests.get(url, headers=UA).content)
- img = Image.open(fd)
- drw = ImageDraw(img)
- drw.text((0,0), product, fill=(255,40,40), font=truetype("OpenSans-Light.ttf", 22))
- img.show()
- PRODUCTS = """
- 3SU1550-0AA10-0AA0
- 3SU1400-1AA10-1BA0
- 6XV1870-8AH10
- 3SU1400-1AA10-1CA0
- 3SU1052-2BF10-0AA0
- 3SU1051-6AA30-0AA0
- 3SU1051-6AA40-0AA0
- 3SU1051-6AA20-0AA0
- 3SU1050-4BF01-0AA0
- 3SU1050-1LB20-0AA0
- 3SU1051-0AB50-0AA0
- 3SU1401-1BB50-1AA0
- 3SU1401-1BB40-1AA0
- 3SU1401-1BB30-1AA0
- 3SU1401-1BB20-1AA0
- """.strip().splitlines()
- for p in PRODUCTS:
- product, source = get_picture(p)
- img = show_img(source, product)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement