爬虫gb2312编码网站时的问题?

我要获取a标签的文本我这样写:

--coding:utf-8--

import time
from urllib.request import urlopen
from bs4 import BeautifulSoup
import re
import chardet

html = urlopen("http://www.gdmzzx.com/html/xiaoyuandongtai/")
bsObj = BeautifulSoup(html)
list_all = bsObj.findAll("a",href = re.compile("/html/xiaoyuandongtai/.+"))
for each in list_all:


print(isinstance(each.get_text(),str))
print(each.get_text())
#print(chardet.detect(each))
#print(each.get_text().encode("utf-8"))

但是得到一团乱码 我应该怎么写?

我知道怎么写了
bsObj = BeautifulSoup(html,fromEncoding = "gbk")

阅读 3k
2 个回答

bsObj = BeautifulSoup(html.read())

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题