无法使用python beautifulsoup从webscraping将charset 1253转换为utf-8

时间:2019-03-23 12:22:53

标签: python python-3.x web-scraping beautifulsoup

我试图通过Web抓取具有html字符集部分的网页

<meta http-equiv="Content-Type" content="text/html; charset=windows-1253">

整个html而不是希腊字符显示以下内容

我得到像这样的人物

'¢ìåóá  ÄéáèÝóéìï'
'20,65\xa0\x80'

我尝试将其转换为

price.text.strip().decode('cp1253').encode('utf8')

soup = BeautifulSoup(Myhtml, 'html.parser').decode('cp1251').encode('utf8')

但同样只有无效字符

1 个答案:

答案 0 :(得分:1)

经过多次测试,我得出以下结论

if r.status_code == 200:
    r.encoding = 'cp1253'
    Myhtml = r.text