无法使用python beautifulsoup到utf-8将网页抓取转换为charset 1253

问题描述 投票:0回答:1

我试图用html charset部分网页抓取一个网页

<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')

但再一次,只有无效的人物

python python-3.x web-scraping beautifulsoup
1个回答
2
投票

经过多次测试后,我最终得到以下结论

if r.status_code == 200:
    r.encoding = 'cp1253'
    Myhtml = r.text
© www.soinside.com 2019 - 2024. All rights reserved.