67def response(resp):
68 results = []
69
70 dom = html.fromstring(resp.text)
71 for result in eval_xpath_list(dom, "//article[contains(@class, 'listview__item')]"):
72 content = []
73 for spec in eval_xpath_list(result, ".//div[contains(@class, 'specs-grid__item')]"):
74 content.append(f"{extract_text(eval_xpath(spec, './dt'))}: {extract_text(eval_xpath(spec, './dd'))}")
75
76 metadata = [
77 extract_text(eval_xpath(result, ".//div[contains(@class, 'stars-rating-label')]")),
78 extract_text(eval_xpath(result, ".//div[contains(@class, 'listview__offercount')]")),
79 ]
80
81 item = {
82 'template': 'products.html',
83 'url': (
84 base_url + "/" + extract_text(eval_xpath(result, ".//a[contains(@class, 'listview__name-link')]/@href"))
85 ),
86 'title': extract_text(eval_xpath(result, ".//h3[contains(@class, 'listview__name')]")),
87 'content': ' | '.join(content),
88 'thumbnail': extract_text(eval_xpath(result, ".//img[contains(@class, 'listview__image')]/@src")),
89 'metadata': ', '.join(item for item in metadata if item),
90 }
91
92 best_price = extract_text(eval_xpath(result, ".//a[contains(@class, 'listview__price-link')]")).split(" ")
93 if len(best_price) > 1:
94 item["price"] = f"Bestes Angebot: {best_price[1]}€"
95 results.append(item)
96
97 return results