Scrapy 0.24 Documentation6 More important, if you type response.selector you will access a selector object you can use to query the response, and convenient shortcuts like response.xpath() and response.css() mapping to response occur. xpath(query) Find nodes matching the xpath query and return the result as a SelectorList instance with all ele- ments flattened. List elements implement Selector interface too. query is a string containing the XPATH query to apply. Note: For convenience this method can be called as response.xpath() css(query) Apply the given CSS selector and return a SelectorList instance. query is a string containing0 码力 | 222 页 | 988.92 KB | 1 年前3
Scrapy 0.22 DocumentationMySpider(Spider): # ... def parse(self, response): sel = Selector(response) # Using XPath query print sel.xpath(’//p’) # Using CSS query print sel.css(’p’) # Nesting queries print sel.xpath(’//div[@foo="bar"]’).css(’span#bold’) 22.0 xpath(query) Find nodes matching the xpath query and return the result as a SelectorList instance with all ele- ments flattened. List elements implement Selector interface too. query is a string string containing the XPATH query to apply. css(query) Apply the given CSS selector and return a SelectorList instance. query is a string containing the CSS selector to apply. In the background, CSS queries0 码力 | 199 页 | 926.97 KB | 1 年前3
Scrapy 1.3 Documentation['Quotes to Scrape'] There are two things to note here: one is that we’ve added ::text to the CSS query, to mean we want to select only the text elements directly insideelement. If we don’t specify the quote HTML elements with: >>> response.css("div.quote") Each of the selectors returned by the query above allows us to run further queries over their sub-elements. Let’s assign the first selector to Request(next_page, callback=self.parse) def parse_author(self, response): def extract_with_css(query): return response.css(query).extract_first().strip() yield { 'name': extract_with_css('h3.author-title::text') 0 码力 | 272 页 | 1.11 MB | 1 年前3
Scrapy 1.2 Documentation['Quotes to Scrape'] There are two things to note here: one is that we’ve added ::text to the CSS query, to mean we want to select only the text elements directly insideelement. If we don’t specify the quote HTML elements with: >>> response.css("div.quote") Each of the selectors returned by the query above allows us to run further queries over their sub-elements. Let’s assign the first selector to Request(next_page, callback=self.parse) def parse_author(self, response): def extract_with_css(query): return response.css(query).extract_first().strip() yield { 'name': extract_with_css('h3.author-title::text') 0 码力 | 266 页 | 1.10 MB | 1 年前3
Scrapy 1.1 DocumentationDocumentation, Release 1.1.3 There are two things to note here: one is that we’ve added ::text to the CSS query, to mean we want to select only the text elements directly insideelement. If we don’t specify the quote HTML elements with: >>> response.css("div.quote") Each of the selectors returned by the query above allows us to run further queries over their sub-elements. Let’s assign the first selector to Request(next_page, callback=self.parse) def parse_author(self, response): def extract_with_css(query): return response.css(query).extract_first().strip() 18 Chapter 2. First steps Scrapy Documentation, Release 0 码力 | 260 页 | 1.12 MB | 1 年前3
Scrapy 2.10 Documentationtry selecting elements using CSS with the response object: >>> response.css("title") [query='descendant-or-self::title' data=' Quotes to Scrape '>] The result of running response ['Quotes to Scrape'] There are two things to note here: one is that we’ve added ::text to the CSS query, to mean we want to select only the text elements directly insideelement. If we don’t specify Scrapy selectors also support using XPath expressions: >>> response.xpath("//title") [ query='//title' data=' Quotes to Scrape '>] >>> response.xpath("//title/text()").get() 'Quotes0 码力 | 419 页 | 1.73 MB | 1 年前3
Scrapy 2.9 Documentationtry selecting elements using CSS with the response object: >>> response.css("title") [query='descendant-or-self::title' data=' Quotes to Scrape '>] The result of running response ['Quotes to Scrape'] There are two things to note here: one is that we’ve added ::text to the CSS query, to mean we want to select only the text elements directly insideelement. If we don’t specify Scrapy selectors also support using XPath expressions: >>> response.xpath("//title") [ query='//title' data=' Quotes to Scrape '>] >>> response.xpath("//title/text()").get() 'Quotes0 码力 | 409 页 | 1.70 MB | 1 年前3
Scrapy 0.24 DocumentationMore important, if you type response.selector you will access a selector object you can use to query the response, and convenient shortcuts like response.xpath() and response.css() mapping to response occur. xpath(query) Find nodes matching the xpath query and return the result as a SelectorList instance with all elements flattened. List elements implement Selector interface too. query is a string containing the XPATH query to apply. Note For convenience this method can be called as response.xpath() css(query) Apply the given CSS selector and return a SelectorList instance. query is a string containing0 码力 | 298 页 | 544.11 KB | 1 年前3
Scrapy 1.0 Documentationoccur. xpath(query) Find nodes matching the xpath query and return the result as a SelectorList instance with all ele- ments flattened. List elements implement Selector interface too. query is a string containing the XPATH query to apply. 48 Chapter 3. Basic concepts Scrapy Documentation, Release 1.0.7 Note: For convenience, this method can be called as response.xpath() css(query) Apply the given CSS CSS selector and return a SelectorList instance. query is a string containing the CSS selector to apply. In the background, CSS queries are translated into XPath queries using cssselect library and run0 码力 | 244 页 | 1.05 MB | 1 年前3
Scrapy 0.20 DocumentationMySpider(BaseSpider): # ... def parse(self, response): sel = Selector(response) # Using XPath query print sel.xpath(’//p’) # Using CSS query print sel.css(’p’) # Nesting queries print sel.xpath(’//div[@foo="bar"]’).css(’span#bold’) occur. xpath(query) Find nodes matching the xpath query and return the result as a SelectorList instance with all ele- ments flattened. List elements implement Selector interface too. query is a string string containing the XPATH query to apply. css(query) Apply the given CSS selector and return a SelectorList instance. query is a string containing the CSS selector to apply. In the background, CSS queries0 码力 | 197 页 | 917.28 KB | 1 年前3
共 62 条
- 1
- 2
- 3
- 4
- 5
- 6
- 7













