How do I open all the links and save the images into a folder in a specific directory on my pc?

42 Views Asked by At

Code:

import urllib.request
from bs4 import BeautifulSoup
from requests import get
import requests
import dload
import pandas as pd
pd.set_option('display.max_colwidth', None)

week_11_picURL = "https://www.packers.com/photos/game-photos-packers-at-vikings-week-11-2021#9258618e-e793-41ae-8d9a-d3792366dcbb"


response = get(week_11_picURL)
print(response)

html_page = requests.get(week_11_picURL)
soup = BeautifulSoup(html_page.content, 'html.parser')
image = soup.findAll('div', class_="nfl-c-photo-album__picture-wrapper")

data = []

for x in soup.select('.nfl-c-photo-album__picture-wrapper picture source:first-child'):
    try:
        data.append(x['srcset'].split(',')[0])
    except:
        data.append(x['data-srcset'].split(',')[0])

data

test_url = "https://static.clubs.nfl.com/image/private/t_new_photo_album/f_auto/packers/f6jcqnmhbzs2dyvepa8z.jpg"

df = pd.DataFrame(data)
replace = df.replace(["/t_lazy", "1x"], "", regex=True)

folder = "f:/nfl pics/packers/week 11 - at vikings"
save = dload.save_multi(url_list=replace, dir=folder, max_threads=1, tsleep=0.05)

replace data:

                                                                                                         0
0    https://static.clubs.nfl.com/image/private/t_new_photo_album/f_auto/packers/hjmcucejx2vmfshjkdkj.jpg 
1    https://static.clubs.nfl.com/image/private/t_new_photo_album/f_auto/packers/rgsvjp6sxu89ditolacv.jpg 
2    https://static.clubs.nfl.com/image/private/t_new_photo_album/f_auto/packers/zsogvqrqgaauqcdgejde.jpg 
3    https://static.clubs.nfl.com/image/private/t_new_photo_album/f_auto/packers/jyegqthuab2hsuygirqp.jpg 
4    https://static.clubs.nfl.com/image/private/t_new_photo_album/f_auto/packers/kwsq1fvn41f6kzqo4nkl.jpg 
etc.

The error I get from using my "save" function is:

Traceback (most recent call last):
  File "location", line 174, in save_multi
    with open(url_list) as f:
TypeError: expected str, bytes or os.PathLike object, not DataFrame

I'm trying to find away to automatically open all the links from the data in "replace" and save the respected images in the directory labeled "folder". When I try to use my "save" function I get the error above. How do I fix this issue or is there a more efficient way to go about this?

0

There are 0 best solutions below