DEV Community

Cover image for 5 Schritte zum Scraping mehrerer Bilder mit Python
hanna Fischer
hanna Fischer

Posted on

5 Schritte zum Scraping mehrerer Bilder mit Python

Schritt 1: Installieren Sie die erforderlichen Python-Bibliotheken

pip install beautifulsoup4
pip install requests
pip install pillow # For saving images

Schritt 2: Stellen Sie eine GET-Anfrage an die URL der Website

import requests
url = "..."
response = requests.get(url)

Schritt 3: Parsen des HTML mit Beautiful Soup

from bs4 import BeautifulSoup
soup = BeautifulSoup(response.text, "html.parser")

Schritt 4: Alle Tags auf der Seite finden

images = soup.find_all("img")

Schritt 5: Durchlaufen Sie jeden Tag und extrahieren Sie die Bild-URL aus dem 'src'-Attribut

for image in images:
img_url = image['src']

Vorteile:

  • Volle Kontrolle und Anpassungsmöglichkeiten
  • Flexibilität bei der Anpassung des Skripts für verschiedene Websites

Nachteile:

  • Erfordert Programmierkenntnisse in Python
  • Weniger benutzerfreundlich als ein visuelles Tool

Für Benutzer ohne Programmierkenntnisse ist Octoparse ein visueller Web Scraper, der verwendet werden kann, um mehrere Bilder von Websites mit einem einfachen Drag-and-Drop-Prozess zu scrapen.

Octoparse bietet über 100 benutzerfreundliche Vorlagen, um Daten zu extrahieren. Über 30.000 Nutzer verwenden die Vorlagen.

Image description

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

AWS GenAI Live!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️