Home  >  Q&A  >  body text

python - Requests抓下来的数据有奇怪的编码问题

代码如图,爬的是bilibili的搜索页面,但是print出来的数据全是这种乱码,已知这个网页的确是用的utf-8

import requests
word = input('>')
payload = {'keyword':word}
r = requests.get('http://search.bilibili.com/all', params=payload)
print(r.text.encode('utf-8'))
ringa_leeringa_lee2762 days ago393

reply all(1)I'll reply

  • 迷茫

    迷茫2017-04-18 10:17:32

    r = requests.get(url, proxies=proxies)
    r.encoding = r.apparent_encoding
    print r.text

    This is a relatively simple method that is suitable for most encodings

    reply
    0
  • Cancelreply