第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

不曉得錯哪了。。。說是有什么中文字符

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

正在回答

5 回答

line 14:將'html,parser' 更改成'html.parser' ,你將參數(shù)敲錯了,正確值是html.parser

0 回復(fù) 有任何疑惑可以回復(fù)我~

在代碼最前面加上#coding=utf-8

同時,把soup?=?BeautifulSoup(html_doc,'html,parser',?from_encoding='utf_8')替換成soup?=?BeautifulSoup(html_doc,'html,parser')

再試試?

0 回復(fù) 有任何疑惑可以回復(fù)我~

在代碼最前面加上# coding:utf8

0 回復(fù) 有任何疑惑可以回復(fù)我~

1、你的utf-8寫成了utf_8,不是下劃線,所以會報你指定的編碼沒定義

2、加from_encoding參數(shù)會警告

warnings.warn("You?provided?Unicode?markup?but?also?provided?a?value?for?from_encoding.?Your?from_encoding?will?be?ignored.")

,不影響輸出結(jié)果,如果不想看這個警告的話,就把

soup?=?BeautifulSoup(html_doc,?'html.parser',?from_encoding='utf-8')

改成

soup?=?BeautifulSoup(html_doc,?'html.parser')

https://img1.sycdn.imooc.com//5ce96fa00001eb3909330443.jpg

1 回復(fù) 有任何疑惑可以回復(fù)我~

可以試試把print('獲取所有鏈接')中的中文翻譯成英文

1 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消
Python開發(fā)簡單爬蟲
  • 參與學(xué)習(xí)       227603    人
  • 解答問題       1288    個

本教程帶您解開python爬蟲這門神奇技術(shù)的面紗

進入課程

不曉得錯哪了。。。說是有什么中文字符

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號