python爬蟲自動解決字符編碼問題

In [34]: import requests
    ...:
    ...: response = requests.get('http://www.dytt8.net/index.htm')
    ...: print(response.text[200:300])
    ...:
-Type content="text/html; charset=gb2312">
<title>μ?ó°ììì?_?a·?μ?ó°_??à×μ?ó°????</title>
<META con

In [35]: response.apparent_encoding
Out[35]: 'GB2312'

In [36]: response.encoding
Out[36]: 'ISO-8859-1'

In [37]: response.encoding = response.apparent_encoding

In [38]: response.text[200:300]
Out[38]: '-Type content="text/html; charset=gb2312">\r\n<title>電影天堂_免費電影_迅雷電影下載</title>\r\n<META content="免費電影下載,電'
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章