Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何从json文件中删除\n_Python 3.x_Scrapy - Fatal编程技术网

Python 3.x 如何从json文件中删除\n

Python 3.x 如何从json文件中删除\n,python-3.x,scrapy,Python 3.x,Scrapy,当我尝试使用terminal将刮取的数据保存在json文件中时,在品牌和品牌名称之后有一个\n({“Brand”:“\n Libra\n”,“Price”:“$24.95”},)。 如何解决这个问题 import scrapy class GlassSpider(scrapy.Spider): name = 'glass' allowed_domains = ['www.glassesshop.com'] start_urls = ['https://www.glas

当我尝试使用terminal将刮取的数据保存在json文件中时,在品牌和品牌名称之后有一个\n({“Brand”:“\n Libra\n”,“Price”:“$24.95”},)。 如何解决这个问题

import scrapy


class GlassSpider(scrapy.Spider):
    name = 'glass'
    allowed_domains = ['www.glassesshop.com']
    start_urls = ['https://www.glassesshop.com/bestsellers/']

    def parse(self, response):
        for item in response.xpath("//div[@class='col-12 pb-5 mb-lg-3 col-lg-4 product-list-row text-center product-list-item']"):
            yield {
                'Brand': item.xpath(".//div[@class='p-title']/a/text()").get(),
                'Price': item.xpath(".//div[@class='product-title p-tab p-tab-13145']/span/text()").get()
            }

您可以使用
str
replace
方法:

。。。
屈服{
'Brand':item.xpath(“.//div[@class='p-title']/a/text()”).get(“”)。replace(“\n”,”),
“Price”:item.xpath(“.//div[@class='product-title p-tab p-tab-13145']]/span/text()”)。get(“”)。replace(“\n”,“”)
}