python - 使用 SCRAPY 抓取特殊字符
问题描述
我正在用丹麦语刮一页。我在输出时遇到问题。输出包含许多特殊字符,例如(Ã¥, Ã, Ã¥, æ)
,它与页面上的不同。
我怎样才能像在页面上一样刮掉文字?
示例链接: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,
}
解决方案
您可以在.encode('utf8')
之后添加get()
或getall()
Scrapy 将数据提取为 unicode 字符串,这可以帮助您了解 unicode 和 UTF-8。
推荐阅读
- gremlin - Is there an efficient way to see how many edges and verticies were created in a gremlin Upsert?
- java - 文件中的填充/未填充矩形
- openshift - OKD 4.5 单节点安装
- javascript - 带有查询参数的 Firebase 函数 GET 请求返回 400 错误
- reactjs - 使用 react-router-dom 匹配 url 路径时如何防止 React 组件卸载
- google-apps-script - 使用电子表格的工作表名称填充行
- python - 多维张量上的感知器
- javascript - 启用远程调试时禁用导航超时
- mysql - 无法将我的 symfony 5 应用程序与 mysql 连接:postgresql 是强制的
- javascript - 通过浏览器访问服务器上的 html 文件