Deprecated: Return type of Lime\App::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/heraudcoyp/www/admin/lib/Lime/App.php on line 1357

Deprecated: Return type of Lime\App::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/heraudcoyp/www/admin/lib/Lime/App.php on line 1346

Deprecated: Return type of Lime\App::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/heraudcoyp/www/admin/lib/Lime/App.php on line 1342

Deprecated: Return type of Lime\App::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/heraudcoyp/www/admin/lib/Lime/App.php on line 1361

Deprecated: Creation of dynamic property MongoHybrid\MongoLite::$db is deprecated in /home/heraudcoyp/www/admin/lib/MongoHybrid/MongoLite.php on line 20

Deprecated: Return type of MongoLite\Cursor::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/heraudcoyp/www/admin/lib/MongoLite/Cursor.php on line 254

Deprecated: Return type of MongoLite\Cursor::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/heraudcoyp/www/admin/lib/MongoLite/Cursor.php on line 263

Deprecated: Return type of MongoLite\Cursor::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/heraudcoyp/www/admin/lib/MongoLite/Cursor.php on line 259

Deprecated: Return type of MongoLite\Cursor::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/heraudcoyp/www/admin/lib/MongoLite/Cursor.php on line 267

Deprecated: Return type of MongoLite\Cursor::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/heraudcoyp/www/admin/lib/MongoLite/Cursor.php on line 247
Aspirateur des images du site Baunetz – heraud.co
n°32
Aspirateur des images du site Baunetz
Web, Python
30 sept 2020

Script Python pour automatiser le téléchargement des images des galeries du site d'architecture Baunetz et Baunetz Architekten. Nécessite Python et les librairies Requests et BeautifulSoup (commandes pip dans le code ci-dessous).

#! python3

import re
import shutil
import requests # "pip install requests" to install package
from bs4 import BeautifulSoup # "pip install beautifulsoup4" to install package
headers = {'User-Agent': 'Mozilla/5.0'}

inputURL = input("Adresse de la page Baunetz à aspirer :")

#Functions
def downloadFile(url):
    url = url.replace("\\","")
    filename = url.split("/")[-1]
    responseImg = requests.get(url, stream=True)
    with open(filename, 'wb') as out_file:
        shutil.copyfileobj(responseImg.raw, out_file)
        del responseImg

def batchDownload(urls):
    print (len(urls),"image(s) trouvée(s).")
    c = 1
    for url in urls:
        downloadFile(url)
        print("Téléchargement", c, "/", (len(urls)))
        c += 1



#Patterns
patternBaunetz = re.compile("^https?://(www.)?baunetz.de/meldungen/([^.]*).html$")
patternBaunetzArchitekten = re.compile("^https?://(www.)?baunetz-architekten.de/([^/]*)/([^/]*)/projekt/([^/]*)$")


# Baunetz
if patternBaunetz.match(inputURL):
    response = requests.get(inputURL, headers=headers)
    soup = BeautifulSoup(response.text,"html.parser")

    scriptTags = soup.find_all("script")

    for scriptTag in scriptTags:
        s = str(scriptTag)
        if s.find("xxlGalerie.xxlimages") >= 0:
           urls = re.findall(r"'url': '(https?://[^']*)'",s)
           batchDownload(urls)

    del response
else:
    print("L'adresse ne correspond pas à une page Baunetz.")


#Baunetz Architekten
if patternBaunetzArchitekten.match(inputURL):
    urls = []
    response = requests.get(inputURL, headers=headers)
    soup = BeautifulSoup(response.text,"html.parser")

    #cover img
    coverImg = soup.select("div.project-detail-image img")
    url = coverImg[0].get("data-src")
    urls.append(url)

    #imgs on landing page
    galleryImgs = soup.select("div.project-detail-gallery__image img")
    for img in galleryImgs:
        url = img.get("data-src")
        urls.append(url)

    #more imgs link (completes the slideshow)
    moreImgs = soup.select("div[data-additional-images]")
    s = str(moreImgs[0].get("data-additional-images"))
    moreImgsUrls = re.findall(r'"src":"(https:[^"]*)',s)
    for moreImgsUrl in moreImgsUrls:
        urls.append(moreImgsUrl)

    batchDownload(urls)
    del response
else:
    print("L'adresse ne correspond pas à une page Baunetz Architekten.")


# End
input("Press Enter to close")

c. héraud-louisadat

architecte & développeur
67200 Strasbourg
heraud-arobase-laponies-point-fr

*1992, Strasbourg.

Diplômé d'état en 2016 de l'ENSA Paris-Malaquais et de la RWTH Aachen et habilité à maîtrise d'oeuvre en nom propre (HMONP) en 2019, j'ai travaillé pour diverses agences d'architecture à Paris et Berlin puis fait de la recherche en histoire de l'art sur l'architecture Heimatschutz. J'ai fondé l'agence Atkinson-Héraud Architectes en 2023 avec Isabelle Atkinson-Evans. Je développe également des applications pour le Web et la 3D.

Amis, famille et blogroll : Anaïs Héraud-Louisadat, Héraud–Baumann, Till Baumann, Antoine Le Dreff, Station Zéro, BALT.

alsace europe