不曉得錯哪了。。。說是有什么中文字符
from?bs4?import?BeautifulSoup html_doc?=?""" <html><head><title>The?Dormouse's?story</title></head> <body> <p?class="title"><b>The?Dormouse's?story</b></p> <p?class="story">Once?upon?a?time?there?were?three?little?sisters;?and?their?names?were<a?>Elsie</a>, <a?>Lacie</a>?and <a?>Tillie</a>;and?they?lived?at?the?bottom?of?a?well.</p> <p?class="story">...</p> """ soup?=?BeautifulSoup(html_doc,'html,parser',?from_encoding='utf_8') print('獲取所有連接')links?=?soup.find_all('a') for?link?in?links:???? ????print(link.name,?link['href'],?link.get_text())
#報錯
SyntaxError: Non-UTF-8 code starting with '\xbb' in file C:\Users\未來人類\Desktop\imooc\test\test_bs4.py on line 18, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
2020-09-10
line 14:將'html,parser' 更改成'html.parser' ,你將參數(shù)敲錯了,正確值是html.parser
2020-08-31
在代碼最前面加上#coding=utf-8
同時,把
soup?
=
?BeautifulSoup(html_doc,
'html,parser'
,?from_encoding
=
'utf_8'
)
替換成soup?
=
?BeautifulSoup(html_doc,
'html,parser'
)
再試試?
2020-08-04
在代碼最前面加上# coding:utf8
2019-05-26
1、你的utf-8寫成了utf_8,不是下劃線,所以會報你指定的編碼沒定義
2、加from_encoding參數(shù)會警告
,不影響輸出結(jié)果,如果不想看這個警告的話,就把
改成
2019-05-24
可以試試把print('獲取所有鏈接')中的中文翻譯成英文