Avito DOM leaks inline <style>.css-XXX{...}</style> inside the location <p>,
which gets pulled by .text(strip=True). Add _clean_address() helper that strips
CSS rules + post-address noise (Площадь N года, от N мин.), apply at extraction
site. Also applied to address_full in avito_detail.py via import from avito.py.
Backfill migration cleans the ~hundreds of historical rows.
Source: estimate a0a0b820-e8a8-4eee-aa73-0ab3b98ac233 analog #4.
24 lines
814 B
Python
24 lines
814 B
Python
from app.services.scrapers.avito import _clean_address
|
||
|
||
|
||
def test_strips_css_noise():
|
||
raw = (
|
||
"ул. Токарей, 56к1Площадь 1905 года.css-39hgr0{fill:currentColor;"
|
||
"height:1em;box-sizing:border-box;}.css-39hgr0:focus{outline:none;}"
|
||
"от 31 мин.Геологическая.css-39hgr0{...}"
|
||
)
|
||
assert _clean_address(raw) == "ул. Токарей, 56к1"
|
||
|
||
|
||
def test_clean_address_passthrough():
|
||
assert _clean_address("ул. Малышева, 1") == "ул. Малышева, 1"
|
||
|
||
|
||
def test_clean_handles_none():
|
||
assert _clean_address(None) is None
|
||
assert _clean_address("") is None
|
||
assert _clean_address(" ") is None
|
||
|
||
|
||
def test_clean_strips_trailing_punctuation():
|
||
assert _clean_address("ул. Ленина, 5,") == "ул. Ленина, 5"
|