86def response(resp):
87 results = []
88 text = resp.text
89
90 if is_alibaba_captcha(text):
91 raise SearxEngineCaptchaException(
92 suspended_time=900, message="Alibaba CAPTCHA detected. Please try again later."
93 )
94
95 if quark_category == 'images':
96 data = json.loads(text)
97 for item in data.get('data', {}).get('hit', {}).get('imgInfo', {}).get('item', []):
98 try:
99 published_date = datetime.fromtimestamp(int(item.get("publish_time")))
100 except (ValueError, TypeError):
101 published_date = None
102
103 results.append(
104 {
105 "template": "images.html",
106 "url": item.get("imgUrl"),
107 "thumbnail_src": item.get("img"),
108 "img_src": item.get("bigPicUrl"),
109 "title": item.get("title"),
110 "source": item.get("site"),
111 "resolution": f"{item['width']} x {item['height']}",
112 "publishedDate": published_date,
113 }
114 )
115
116 if quark_category == 'general':
117
118 source_category_parsers = {
119 'addition': parse_addition,
120 'ai_page': parse_ai_page,
121 'baike_sc': parse_baike_sc,
122 'finance_shuidi': parse_finance_shuidi,
123 'kk_yidian_all': parse_kk_yidian_all,
124 'life_show_general_image': parse_life_show_general_image,
125 'med_struct': parse_med_struct,
126 'music_new_song': parse_music_new_song,
127 'nature_result': parse_nature_result,
128 'news_uchq': parse_news_uchq,
129 'ss_note': parse_ss_note,
130
131 'ss_doc': parse_ss_doc,
132 'ss_kv': parse_ss_doc,
133 'ss_pic': parse_ss_doc,
134 'ss_text': parse_ss_doc,
135 'ss_video': parse_ss_doc,
136 'baike': parse_ss_doc,
137 'structure_web_novel': parse_ss_doc,
138 'travel_dest_overview': parse_travel_dest_overview,
139 'travel_ranking_list': parse_travel_ranking_list,
140 }
141
142 pattern = r'<script\s+type="application/json"\s+id="s-data-[^"]+"\s+data-used-by="hydrate">(.*?)</script>'
143 matches = re.findall(pattern, text, re.DOTALL)
144
145 for match in matches:
146 data = json.loads(match)
147 initial_data = data.get('data', {}).get('initialData', {})
148 extra_data = data.get('extraData', {})
149
150 source_category = extra_data.get('sc')
151
152 parsers = source_category_parsers.get(source_category)
153 if parsers:
154 parsed_results = parsers(initial_data)
155 if isinstance(parsed_results, list):
156
157 results.extend(parsed_results)
158 else:
159
160 results.append(parsed_results)
161
162 return results
163
164