Python Forum
Can not make this image downloader work
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can not make this image downloader work
#5
(Jun-23-2020, 11:50 AM)Blue Dog Wrote: I have the script in its own folder so the maps should be saved in the folder that the script is in. Maybe a while loop will work better. I am just lost on saving the images.
The loop is already done in my code,so inside this loop can use os.path.basename to get correct names of images when save.
Then to get the content(bytes) of images need also to open links with Requests,then can save.
Here also put in a progress bar with tqdm.
import requests
from bs4 import BeautifulSoup
import os
# pip install tqdm
from tqdm import tqdm

url = 'http://legacy.lib.utexas.edu/maps/topo/indiana/'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
maps = soup.select_one('#actualcontent > ul')
map_link = maps.find_all('a')[:-1]
for link in tqdm(map_link):
    img_name = os.path.basename(link.get('href'))
    #print(img_name)
    img = requests.get(link.get('href'))
    with open(img_name, 'wb') as f_out:
            f_out.write(img.content)
Reply


Messages In This Thread
RE: Can not make this image downloader work - by snippsat - Jun-23-2020, 01:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  m3u8 using build-in browser downloader? kucingkembar 3 420 Mar-29-2024, 01:47 AM
Last Post: kucingkembar
  RFC downloader not working sidsr003 2 2,790 Dec-19-2018, 09:31 PM
Last Post: snippsat
  How to make my code work with asyncio? DevinGP 0 2,742 Jan-09-2018, 06:21 PM
Last Post: DevinGP
  Multiple File Downloader Josh_Python890 1 2,521 Sep-16-2017, 11:19 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020