async def _parse_html(cls, *, html_etree: etree._Element): if html_etree is None: raise ValueError("html_etree is expected") item_ins = cls() for field_name, field_value in getattr(item_ins, '__fields', {}).items(): if not field_name.startswith('target_'): clean_method = getattr(item_ins, f'clean_{field_name}', None) value = field_value.extract(html_etree=html_etree) if clean_method is not None: try: value = await clean_method(value) except TypeError as e: if 'await' in str(e): raise InvalidFuncType( f'<Item: clean_method must be a coroutine function>' ) else: raise TypeError(e) except IgnoreThisItem: item_ins.ignore_item = True setattr(item_ins, field_name, value) item_ins.results[field_name] = value return item_ins
async def _parse_html(cls, *, html_etree: etree._Element): if html_etree is None: raise ValueError("<Item: html_etree is expected>") item_ins = cls() fields_dict = getattr(item_ins, "__fields", {}) for field_name, field_value in fields_dict.items(): if field_name != "target_item": clean_method = getattr(item_ins, f"clean_{field_name}", None) value = field_value.extract(html_etree) if clean_method is not None and callable(clean_method): try: aws_clean_func = clean_method(value) if isawaitable(aws_clean_func): value = await aws_clean_func else: raise InvalidFuncType( f"<Item: clean_method must be a coroutine function>" ) except IgnoreThisItem: item_ins.ignore_item = True setattr(item_ins, field_name, value) item_ins.results[field_name] = value return item_ins