get() == extract_first()
返回的是一个list,里面包含了多个string,如果只有一个string,则返回['我很孤独']这样的形式
getall() == extract()
返回的是string,list里面第一个string
In [17]: type(response.xpath('//*[@id="waterfall"]/div[1]/a/div[2]/span/text()'))
Out[17]: scrapy.selector.unified.SelectorList
In [18]: type(response.xpath('//*[@id="waterfall"]/div[1]/a/div[2]/span/text()')[0])
Out[18]: scrapy.selector.unified.Selector
In [19]: response.xpath('//*[@id="waterfall"]/div[1]/a/div[2]/span/text()')[0].get()
Out[19]: 'DNW-025 彼女が制服に着替えたら。5'
In [20]: response.xpath('//*[@id="waterfall"]/div[1]/a/div[2]/span/text()')[0].getall()
Out[20]: ['DNW-025 彼女が制服に着替えたら。5']
In [21]: response.xpath('//*[@id="waterfall"]/div[1]/a/div[2]/span/text()')[0].extract()
Out[21]: 'DNW-025 彼女が制服に着替えたら。5'
In [22]: response.xpath('//*[@id="waterfall"]/div[1]/a/div[2]/span/text()')[0].extract_first()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-22-9eada5e1e561> in <module>
----> 1 response.xpath('//*[@id="waterfall"]/div[1]/a/div[2]/span/text()')[0].extract_first()
AttributeError: 'Selector' object has no attribute 'extract_first'
In [23]: response.xpath('//*[@id="waterfall"]/div[1]/a/div[2]/span/text()')[0]
Out[23]: <Selector xpath='//*[@id="waterfall"]/div[1]/a/div[2]/span/text()' data='DNW-025 彼女が制服に着替えたら。5'>