我有以下课程:
class PitchforkTracks(scrapy.Spider):
name = "pitchfork_tracks"
allowed_domains = ["pitchfork.com"]
start_urls = [
"http://pitchfork.com/reviews/best/tracks/?page=1",
"http://pitchfork.com/reviews/best/tracks/?page=2",
"http://pitchfork.com/reviews/best/tracks/?page=3",
"http://pitchfork.com/reviews/best/tracks/?page=4",
"http://pitchfork.com/reviews/best/tracks/?page=5",
]
def parse(self, response):
for sel in response.xpath('//div[@class="track-details"]/div[@class="row"]'):
item = PitchforkItem()
item['artist'] = sel.xpath('.//li/text()').extract_first()
item['track'] = sel.xpath('.//h2[@class="title"]/text()').extract_first()
yield item刮掉这个项目:
<h2 class="title" data-reactid="...>“Colours”</h2>然而,这样的打印结果:
{'artist': u'The Avalanches', 'track': u'\u201cColours\u201d'}I应该在哪里以及如何去掉quotes,即\u201c和\u201d
发布于 2016-09-30 02:11:23
在parse(self, response)内部,添加:
item['track'] = sel.xpath('.//h2[@class="title"]/text()').extract_first().strip(u'\u201c\u201d') https://stackoverflow.com/questions/39782247
复制相似问题