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

Method _parse

scrapy/spiders/feed.py:74–99  ·  scrapy/spiders/feed.py::XMLFeedSpider._parse
(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, class="st">"parse_node"):
76 raise NotConfigured(
77 class="st">"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 == class="st">"iternodes":
83 nodes = self._iternodes(response)
84 elif self.iterator == class="st">"xml":
85 if not isinstance(response, TextResponse):
86 raise ValueError(class="st">"Response content isn&class="cm">#x27;t text")
87 selector = Selector(response, type=class="st">"xml")
88 self._register_namespaces(selector)
89 nodes = selector.xpath(fclass="st">"//{self.itertag}")
90 elif self.iterator == class="st">"html":
91 if not isinstance(response, TextResponse):
92 raise ValueError(class="st">"Response content isn&class="cm">#x27;t text")
93 selector = Selector(response, type=class="st">"html")
94 self._register_namespaces(selector)
95 nodes = selector.xpath(fclass="st">"//{self.itertag}")
96 else:
97 raise NotSupported(class="st">"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