编码问题
import urllib.requestfrom bs4 import BeautifulSoup
import re
def main():
url = 'http://baike.baidu.com/item/百度/6699'
response = urllib.request.urlopen(url)
html = response.read()
html.encoding = 'utf-8'
soup = BeautifulSoup(html,"html.parser")
result = soup.select('meta.description')
for each in result:
print(each)
if __name__ == '__main__':
main()
报错:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-11: ordinal not in range(128) https://fishc.com.cn/forum.php?mod=viewthread&tid=177175
页:
[1]