MCPcopy
hub / github.com/scrapy/scrapy / _parse

Method _parse

scrapy/spiders/feed.py:74–99  ·  view source on GitHub ↗
(self, response: Response, **kwargs: Any)

Source from the content-addressed store, hash-verified

72 yield from self.process_results(response, ret)
73
74 def _parse(self, response: Response, **kwargs: Any) -> Any:
75 if not hasattr(self, "parse_node"):
76 raise NotConfigured(
77 "You must define parse_node method in order to scrape this XML feed"
78 )
79
80 response = self.adapt_response(response)
81 nodes: Iterable[Selector]
82 if self.iterator == "iternodes":
83 nodes = self._iternodes(response)
84 elif self.iterator == "xml":
85 if not isinstance(response, TextResponse):
86 raise ValueError("Response content isn't text")
87 selector = Selector(response, type="xml")
88 self._register_namespaces(selector)
89 nodes = selector.xpath(f"//{self.itertag}")
90 elif self.iterator == "html":
91 if not isinstance(response, TextResponse):
92 raise ValueError("Response content isn't text")
93 selector = Selector(response, type="html")
94 self._register_namespaces(selector)
95 nodes = selector.xpath(f"//{self.itertag}")
96 else:
97 raise NotSupported("Unsupported node iterator")
98
99 return self.parse_nodes(response, nodes)
100
101 def _iternodes(self, response: Response) -> Iterable[Selector]:
102 for node in xmliter_lxml(response, self.itertag):

Callers

nothing calls this directly

Calls 8

adapt_responseMethod · 0.95
_iternodesMethod · 0.95
_register_namespacesMethod · 0.95
parse_nodesMethod · 0.95
NotConfiguredClass · 0.90
SelectorClass · 0.90
NotSupportedClass · 0.90
xpathMethod · 0.45

Tested by

no test coverage detected