Scrapy Response Parsing with Callback and Link Following
This is a method that is part of a class. It takes in a response object, a callback function, callback keyword arguments, and a flag indicating whether to follow links or not.\n\nFirst, it checks if a callback function is provided. If so, it calls the callback function with the response and keyword arguments. If the callback function returns an async iterable, it collects all the items in the iterable using the `collect_asyncgen` function and assigns the result to `cb_res`. If the callback function returns an awaitable, it awaits the result and assigns it to `cb_res`. Then, it calls the `process_results` method with the response and `cb_res` to process the results.\n\nAfter processing the results, it iterates over the output of the `iterate_spider_output` function, which takes in `cb_res` and yields either a request or item. This is done to handle the case where the callback function returns multiple requests or items.\n\nNext, if the `follow` flag is `True` and the `_follow_links` attribute of the class is also `True`, it calls the `_requests_to_follow` method with the response to get a list of requests or items to follow. It then iterates over this list and yields each request or item.\n\nIn summary, this method processes the response using a callback function, collects the results, and yields either requests or items to follow or process further.
原文地址: https://www.cveoy.top/t/topic/p3dv 著作权归作者所有。请勿转载和采集!