update autoscraper, add another makellaar
This commit is contained in:
@@ -9,6 +9,7 @@ Usage:
|
||||
|
||||
import re
|
||||
import sys
|
||||
import json
|
||||
|
||||
import httpx
|
||||
from bs4 import BeautifulSoup, Tag
|
||||
@@ -264,6 +265,31 @@ def cmd_details(url: str):
|
||||
alt = img.get("alt", "")
|
||||
print(f" {src} [{alt}]")
|
||||
|
||||
# JSON-LD
|
||||
print("\n=== JSON-LD (schema.org) ===")
|
||||
for tag in soup.select('script[type="application/ld+json"]'):
|
||||
try:
|
||||
ld = json.loads(tag.string)
|
||||
offered = ld.get("itemOffered", {})
|
||||
address = offered.get("address", {})
|
||||
floor_size = offered.get("floorSize", {})
|
||||
fields = {
|
||||
"woningtype": offered.get("@type"),
|
||||
"adres": address.get("streetAddress"),
|
||||
"postcode": address.get("postalCode"),
|
||||
"stad": address.get("addressLocality"),
|
||||
"prijs": ld.get("price"),
|
||||
"woonoppervlak": floor_size.get("value"),
|
||||
"kamers": offered.get("numberOfRooms"),
|
||||
"bouwjaar": offered.get("yearBuilt"),
|
||||
"availability": ld.get("availability"),
|
||||
"image": ld.get("image"),
|
||||
}
|
||||
for k, v in fields.items():
|
||||
mark = "✓" if v is not None else "✗"
|
||||
print(f" {mark} {k:<16} {v!r}")
|
||||
except Exception as e:
|
||||
print(f" parse fout: {e}")
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Entry point
|
||||
|
||||
Reference in New Issue
Block a user