【问题标题】:Encoding problem while web scraping PythonWeb抓取Python时的编码问题
【发布时间】:2020-08-14 11:51:47
【问题描述】:

你知道吗,为什么我会得到这个 ID ССРестра 而不是 ID ГосРеестра。我知道编码存在一些问题,因为它是西里尔文。不知道怎么解决。

抓取网页为link

我的代码是:

dfo_url = "https://opi.dfo.kz/p/ru/DfoObjects/objects/teaser-view/26730?OptionName=ExtraData"
r = requests.get(dfo_url)

tree = html.fromstring(r.content)
tr_elements = tree.xpath('//tr')
#Create empty list
col=[]
i=0
#For each row, store each first element (header) and an empty list
for t in tr_elements[2]:
    i+=1
    name=t.text_content()

    print ('%d:"%s"'%(i,name))
    col.append((name,[]))

【问题讨论】:

    标签: python html web-scraping python-requests cyrillic


    【解决方案1】:

    这可能会解决它,请尝试在打印之前执行此操作:

    name.encode(encoding='UTF-8',errors='strict')
    

    或者试试this链接。

    【讨论】:

    • @Dias 看看this
    • 没问题,如果你愿意,可以接受我的回答,我会用链接更新它:) @Dias
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-22
    • 2021-06-27
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    相关资源
    最近更新 更多