Hack Forums
[Python] I am trying to download all images in a specific Directory on a webserver - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] I am trying to download all images in a specific Directory on a webserver (/showthread.php?tid=6159726)



I am trying to download all images in a specific Directory on a webserver - 0u1law - Jun 20, 2021

I am trying to gather all images in a specific Directory on a webserver but without to know what the name of a jpg file is

for example on www.this.id/the/website are 3 jpg files with the name 1.jpg, adkjf.jpg and 5df_df.jpg

How can i search on this specific link for all jpg files and download them on my Computer ?

I want to use Python Selenium but i have no Access to the Folder but i can look at the pictures if i have the name of the jpg files

Which modules do i need to download every single jpg file ? Any examples for me ?

Im new to this sorry if the question sounds stupid


Thanks in Advance


RE: I am trying to download all images in a specific Directory on a webserver - kray - Jun 20, 2021

You'd effectively be bruteforcing it, there's no reason to use selenium.


RE: I am trying to download all images in a specific Directory on a webserver - 3phase - Jul 15, 2021

You don't need selenium for that,
you can do something like

Code
import requests
from bs4 import BeautifulSoup

url = 'http://thesite.id/what/ever/'
ext = 'jpg'

def listFD(url, ext=''):
    page = requests.get(url).text
    print(page)
    soup = BeautifulSoup(page, 'html.parser')
    return [url + '/' + node.get('href') for node in soup.find_all('a') if node.get('href').endswith(ext)]

for file in listFD(url, ext):
    print(file)