45def response(resp):
46 results = []
47
48 raise_for_httperror(resp)
49 dom = fromstring(resp.text)
50 word = extract_text(dom.xpath(word_xpath))
51
52 definitions = []
53
54 for dict_src in dict_xpath:
55 for src in dom.xpath(dict_src):
56 src_text = extract_text(src.xpath('.//span[@class="entry-head-title"]/text()')).strip()
57
58 src_defs = []
59 for def_item in src.xpath('.//div[contains(@class, "ribbon-element")]'):
60 if def_item.xpath('./div[@class="znacz"]'):
61 sub_defs = []
62 for def_sub_item in def_item.xpath('./div[@class="znacz"]'):
63 def_sub_text = extract_text(def_sub_item).lstrip('0123456789. ')
64 sub_defs.append(def_sub_text)
65 src_defs.append((word, sub_defs))
66 else:
67 def_text = extract_text(def_item).strip()
68 def_link = def_item.xpath('./span/a/@href')
69 if 'doroszewski' in def_link[0]:
70 def_text = f"<a href='{def_link[0]}'>{def_text}</a>"
71 src_defs.append((def_text, ''))
72
73 definitions.append((src_text, src_defs))
74
75 if not definitions:
76 return results
77
78 infobox = ''
79 for src in definitions:
80 infobox += f"<div><small>{src[0]}</small>"
81 infobox += "<ul>"
82 for def_text, sub_def in src[1]:
83 infobox += f"<li>{def_text}</li>"
84 if sub_def:
85 infobox += "<ol>"
86 for sub_def_text in sub_def:
87 infobox += f"<li>{sub_def_text}</li>"
88 infobox += "</ol>"
89 infobox += "</ul></div>"
90
91 results.append(
92 {
93 'infobox': word,
94 'content': infobox,
95 }
96 )
97
98 return results