[英]Scraping special characters with SCRAPY
我正在用丹麥語刮一頁。 我在使用 output 時遇到問題。 output 包含許多特殊字符,例如(Ã¥, Ã, Ã¥, æ)
,它與頁面上的不同。
我怎樣才能像在頁面上一樣刮掉文字?
示例鏈接: https://novaindex.com/dk/leverandoerer/mode-og-tekstiler/arbejdstoej
import scrapy
class MainSpider(scrapy.Spider):
name = 'main'
start_urls = ['https://novaindex.com/dk/leverandoerer/mode-og-tekstiler/arbejdstoej']
def parse(self, response):
details = response.xpath('//a[@class="companyresult "]')
for each in details:
name = each.xpath('normalize-space(.//span[@class="name"]/text())').get()
street = each.xpath('normalize-space(.//span[@class="street"]/text())').get()
city = each.xpath('normalize-space(.//span[@class="city"]/text())').get()
phone = each.xpath('normalize-space(.//span[@class="phone"]/text())').get()
yield {
"Name": name,
"Street Address": street,
"City Address": city,
"Phone": phone,
}
您可以在get()
或getall()
之后添加.encode('utf8')
)
Scrapy 將數據提取為 unicode 字符串,這可能有助於您了解 Abit 關於 unicode 和 ZAE3B3DF9970B59B6523E6078
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.