Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import tkinter as tk
- import requests
- import bs4
- import urllib.parse
- # --- constanst --- (UPPER_CASE names)
- FOLDER = "pictures"
- #FOLDER = "Obrazy"
- # --- functions ---
- def download(): # readable name
- link = ent.get()
- info = requests.get(link)
- code = bs4.BeautifulSoup(info.text, "lxml")#08033007723
- images = code.select("img")
- for image in images:
- src = image.get("src")
- #name = src[pos:]
- name = src.split('/')[-1]
- info_label['text'] = name
- root.update() # to force tkinter to update widgets
- url = urllib.parse.urljoin(link, src)
- infos = requests.get(url)
- files = open(os.path.join(FOLDER, name), 'wb')
- files.write(infos.content)
- files.close()
- info_label['text'] = '< finished >'
- # --- main ---
- root = tk.Tk()
- root.title("Pics Downloader")
- root.geometry("400x200")
- label = tk.Label(root, text="Link to page with image(s):") # no spaces around =
- label.pack(fill='x', padx=5, pady=5)
- ent = tk.Entry(root)
- ent.pack(fill='x', padx=5, pady=(0,5))
- but = tk.Button(root, text="Download", command=download)
- but.pack(fill='x', padx=5, pady=(0,5))
- info_label = tk.Label(root, text="") # label to display downloaded images
- info_label.pack(fill='x', padx=5, pady=5)
- root.mainloop()
Add Comment
Please, Sign In to add comment