Python Scrapy Xpath中的转义逗号

Python Scrapy Xpath中的转义逗号,python,xpath,scrapy,Python,Xpath,Scrapy,在一只刮痒的蜘蛛身上工作 我有这个html: <div class="sliderContent"> <p>some content, some other content</p> <p>some content, some other content</p> <p>some content, some other content</p> <p>some content, some other con

在一只刮痒的蜘蛛身上工作

我有这个html:

<div class="sliderContent">
<p>some content, some other content</p>
<p>some content, some other content</p>
<p>some content, some other content</p>
<p>some content, some other content</p>
</div>
我想对
中的逗号进行转义,并提取所有内容,保留html。我试过这个:

    def parse_dir_contents(self, response):
        for sel in response.xpath('//div[@class="container"]'):
        item = LuItem()
        item['Description'] = sel.xpath('div[@class="content"]/div/div[@class="sliderContent"]//p').extract()[0].replace(',','\,')
        yield item
显然,这适用于第一个
,但如何才能在所有
中实现这一点


从python开始,非常感谢您的帮助

您的解析结果是一个列表,并且您只修改列表[0]中的第一个元素,您需要浏览整个描述列表:

def parse_dir_contents(self, response):
    for sel in response.xpath('//div[@class="container"]'):
        item = LuItem()
        item['Description'] = sel.xpath('div[@class="content"]/div/div[@class="sliderContent"]//p').extract()
        item['Description'] = [ ''.join(field.split(',')) for field in item.get('Description', [])]
        yield item

请添加网站url。我想你可以试试这样的东西:>>>a='一些内容,一些其他内容'>>>a.replace(',','/'))'一些内容/一些其他内容'
def parse_dir_contents(self, response):
    for sel in response.xpath('//div[@class="container"]'):
        item = LuItem()
        item['Description'] = sel.xpath('div[@class="content"]/div/div[@class="sliderContent"]//p').extract()
        item['Description'] = [ ''.join(field.split(',')) for field in item.get('Description', [])]
        yield item