Created
October 28, 2024 15:24
-
-
Save sorryusernameisalreadytaken/8ae67cc662fa38b0ea7832324a7c9dad to your computer and use it in GitHub Desktop.
kleinanzeigen.de - check for item - POC for testing there services against scraping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from bs4 import BeautifulSoup | |
import time | |
# your query as a parameter | |
search_term = "quasi-modo" # just "quasi-modo" with your search query | |
search_url = f"https://www.kleinanzeigen.de/s-suchanfrage.html?keywords={search_term}&categoryId=&locationStr=&locationId=0&radius=0&sortingField=SORTING_DATE&adType=&posterType=&pageNum=1&action=find&maxPrice=&minPrice=&buyNowEnabled=false&shippingCarrier=" | |
def scrape_kleinanzeigen(): | |
response = requests.get(search_url) | |
if response.status_code == 200: | |
soup = BeautifulSoup(response.content, 'html.parser') | |
# parse article | |
ads = soup.find_all("article") # oder spezifische Klasse der Anzeige je nach Seitenstruktur | |
for ad in ads: | |
title = ad.find("a", {"class": "ellipsis"}).text.strip() if ad.find("a", {"class": "ellipsis"}) else "Kein Titel" | |
link = ad.find("a", {"class": "ellipsis"})["href"] if ad.find("a", {"class": "ellipsis"}) else "Kein Link" | |
print(f"Found new item: {title} - {link}") | |
# check contin. the results | |
while True: | |
scrape_kleinanzeigen() | |
time.sleep(600) # Check every 10 min. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment