Unicode issue in scrapy python

…衆ロ難τιáo~ 提交于 2021-02-11 14:16:48

问题


For two hours, I am searching for this topic and I have tried a lot of solutions but noen worked in my case Here's the code first

import scrapy

class HamburgSpider(scrapy.Spider):
    name = 'hamburg'
    #allowed_domains = ['https://www.hamburg.de']
    start_urls = ['https://www.hamburg.de/branchenbuch/hamburg/10239785/n0/']
    custom_settings = {
        'FEED_EXPORT_FORMAT': 'utf-8'
    }

    def parse(self, response):
        #response=response.body.encode('utf-8')
        items = response.xpath("//div[starts-with(@class, 'item')]")
        for item in items:
            business_name = item.xpath(".//h3[@class='h3rb']/text()").get()
            address1 = item.xpath(".//div[@class='address']/p[@class='extra post']/text()[1]").get()
            address2 = item.xpath(".//div[@class='address']/p[@class='extra post']/text()[2]").get()
            phone = item.xpath(".//div[@class='address']/span[@class='extra phone']/text()").get()

            yield {
                'Business Name': business_name,
                'Address1': address1,
                'Address2': address2,
                'Phone Number': phone
            }

In the code I put this line

custom_settings = { 'FEED_EXPORT_FORMAT': 'utf-8' }

The line supposed to deal with the issue of encoding but when exporting the results to csv, I found that the issue is still there. I simply need to show this example of text Poppenbütteler Bogen 29a sa shown on the website. What I found is that the output is different


回答1:


You have the wrong setting name.

FEED_EXPORT_FORMAT is not one of the settings scrapy uses by default, you want FEED_EXPORT_ENCODING instead.



来源:https://stackoverflow.com/questions/64781553/unicode-issue-in-scrapy-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!