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
#1
Hi,
I am trying to make a maps down loader. I got everything working good, but for the last for loop. I been working on this for a lone time. here id the code:

import requests
import bs4 as bs
import urllib.request

url = str(input('URL: '))

opener = urllib.request.build_opener()
opener.add_headers = [{'User-Agent' : 'Mozilla'}]
urllib.request.install_opener(opener)

raw = requests.get(url).text
soup = bs.BeautifulSoup(raw, 'html.parser')
imgs = soup.find_all ('img')
links = []
for img in imgs:
    link = img.get('scr')
    #if 'http://' not in link:
        #link = url + link
    links.append(link)

print('Image detected: ' + str(len(links)))

for i in range(len(links)):
    filename = str(img.jpg) .format(i)
    urllib.request.urlretrieve(links[i], filename)
    print('Done!')
here is the error:



URL: http://legacy.lib.utexas.edu/maps/topo/indiana/
Image detected: 35
Traceback (most recent call last):
File "C:\Users\Kite\Desktop\scraping Images\TUT_7\test_1.py", line 25, in <module>
urllib.request.urlretrieve(links[i], filename)
File "C:\Python36\lib\urllib\request.py", line 246, in urlretrieve
url_type, path = splittype(url)
File "C:\Python36\lib\urllib\parse.py", line 954, in splittype
match = _typeprog.match(url)
TypeError: expected string or bytes-like object

It looks like I need to turn something to a string. If anyone can give me an hand that would be nice.
Reply


Messages In This Thread
Can not make this image downloader work - by Blue Dog - Jun-22-2020, 03:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  m3u8 using build-in browser downloader? kucingkembar 0 65 Yesterday, 10:50 PM
Last Post: kucingkembar
  RFC downloader not working sidsr003 2 2,707 Dec-19-2018, 09:31 PM
Last Post: snippsat
  How to make my code work with asyncio? DevinGP 0 2,695 Jan-09-2018, 06:21 PM
Last Post: DevinGP
  Multiple File Downloader Josh_Python890 1 2,449 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