Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minor issues with Immoscout24 image extraction #517

Merged
merged 3 commits into from
Jan 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions flathunter/crawler/immobilienscout.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re

from bs4 import BeautifulSoup, Tag
from jsonpath_ng import parse
from jsonpath_ng.ext import parse
from selenium.common.exceptions import JavascriptException
from selenium.webdriver import Chrome

Expand Down Expand Up @@ -35,7 +35,9 @@ class Immobilienscout(Crawler):
URL_PATTERN = STATIC_URL_PATTERN

JSON_PATH_PARSER_ENTRIES = parse("$..['resultlist.realEstate']")
JSON_PATH_PARSER_IMAGES = parse("$..galleryAttachments..['@href']")
JSON_PATH_PARSER_IMAGES = parse("$..galleryAttachments"
"..attachment[?'@xsi.type'=='common:Picture']"
"..['@href'].`sub(/(.*\\\\.jpe?g).*/, \\\\1)`")

RESULT_LIMIT = 50

Expand Down Expand Up @@ -145,10 +147,7 @@ def extract_entry_from_javascript(self, entry):
#
# After: https://pictures.immobilienscout24.de/listings/$$IMAGE_ID$$.jpg

images = [
image.value[:image.value.find(".jpg") + 4]
for image in self.JSON_PATH_PARSER_IMAGES.find(entry)
]
images = [image.value for image in self.JSON_PATH_PARSER_IMAGES.find(entry)]

object_id: int = int(entry.get("@id", 0))
return {
Expand Down
Loading