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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

爬出來的頁面內(nèi)容顯示這種亂碼似的文字是怎么回事啊?求教!謝謝!

http://img1.sycdn.imooc.com//56f355e70001f2b214160438.jpg

就是這種,該怎么辦呢?

正在回答

4 回答

def?output_html(self):
????????fout=open('output.html','w',encoding="utf-8")
????????
????????fout.write("<html>")
????????fout.write("<body>")
????????
????????fout.write("<head>")
????????fout.write('<meta?charset="utf-8">')
????????fout.write("</head>")
????????
????????fout.write("<table>")
????????
????????for?data?in?self.datas:
????????????fout.write("<tr>")
????????????fout.write("<td>%s</td>"?%?data['url'])
????????????fout.write("<td>%s</td>"?%?data['title'])
????????????fout.write("<td>%s</td>"?%?data['summary'])
????????????fout.write("</tr>")
????????????
????????fout.write("</table>")
????????fout.write("</body>")
????????fout.write("</html>")
????????
????????fout.close()

試一下這樣吧

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

green_apple7 提問者

謝謝!不過,還是不行。。。
2016-03-25 回復(fù) 有任何疑惑可以回復(fù)我~
#2

us4ever 回復(fù) green_apple7 提問者

我去掉 fout.write("<head>") fout.write('<meta charset="utf-8">') fout.write("</head>") 就會(huì)變成跟你一樣的亂碼,應(yīng)該就是編碼的問題,看看html_parser.py這一句soup=BeautifulSoup(html_cont,'html.parser',from_encoding='utf-8')用的是不是utf-8 不行就換換瀏覽器
2016-03-25 回復(fù) 有任何疑惑可以回復(fù)我~
#3

green_apple7 提問者 回復(fù) us4ever

謝謝你!我的問題解決了,是在<html>后面加上utf-8就好了。非常感謝你!fout.write("<html><meta charset=\"utf-8\" />")
2016-03-26 回復(fù) 有任何疑惑可以回復(fù)我~

謝謝你!我的問題解決了,是在<html>后面加上utf-8就好了。非常感謝你!fout.write("<html><meta charset=\"utf-8\" />")

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

沒有轉(zhuǎn)換編碼格式吧,默認(rèn)是標(biāo)準(zhǔn)編碼,需要轉(zhuǎn)換為utf-8

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

green_apple7 提問者

你好!請(qǐng)問具體該怎么做呢?開頭有注釋,output里也像老師那樣寫了fout.write("<td>%s</td>"%data['title'].encode('utf-8')),還需要再做什么呢?
2016-03-24 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

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

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

進(jìn)入課程

爬出來的頁面內(nèi)容顯示這種亂碼似的文字是怎么回事啊?求教!謝謝!

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

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

幫助反饋 APP下載

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

公眾號(hào)

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