我在Python中运行BS4,代码如下:
import urllib
import requests
from bs4 import BeautifulSoup
from bs4 import UnicodeDammit
with requests.Session() as s:
page = s.get(url)
doc = page.text
soup = BeautifulSoup(doc, "html.parser")
print(soup)
这将生成错误:[解码错误-输出不是utf-8]
使用以下方法会产生相同的错误:
^{pr2}$使用忽略:
soup = BeautifulSoup(page.read().decode('utf-8', 'ignore'))
给我不同的错误:
AttributeError: 'Response' object has no attribute 'read'
目前没有回答
相关问题 更多 >
编程相关推荐