psf/requests-html

When requesting a page that is ISO-8859-1 encoded, HTML is still interpreted as UTF-8

開放

#442 建立於 2021年1月27日

 (3 則留言) (0 個反應) (0 位負責人)Python (976 個分叉)batch import
help wanted

倉庫指標

星標
 (13,555 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

When requesting a page that is ISO-8859-1 encoded:

>>> r = session.get('https://gerda.geus.dk/Gerda/Search')
>>> r.encoding
'ISO-8859-1'
>>> r.html.default_encoding
'ISO-8859-1'
>>> r.html.encoding
'utf8'
>>> r.html.find("option")[-1].text
'Bygge-anl�g'

Expected behavior:

>>> r.html.find("option")[-1].text
'Bygge-anlæg'

As far as I can see, there are two problems:

  • r.html.encoding is incorrectly set
  • r.html.element (The PyQuery instance) does not take encoding into account at all but just assumes utf-8

貢獻者指南