課程
/后端開發(fā)
/Python
/Python開發(fā)簡(jiǎn)單爬蟲
2016-03-24
源自:Python開發(fā)簡(jiǎn)單爬蟲 7-7
正在回答
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()
試一下這樣吧
green_apple7 提問者
us4ever 回復(fù) green_apple7 提問者
green_apple7 提問者 回復(fù) us4ever
評(píng)論欄【發(fā)表】的右邊有一個(gè)【課件下載】。id是標(biāo)簽的唯一標(biāo)識(shí),加上是在頁面上是看不到效果的,如果想獲取這個(gè)標(biāo)簽的時(shí)候通過id就很容易找到了
謝謝你!我的問題解決了,是在<html>后面加上utf-8就好了。非常感謝你!fout.write("<html><meta charset=\"utf-8\" />")
沒有轉(zhuǎn)換編碼格式吧,默認(rèn)是標(biāo)準(zhǔn)編碼,需要轉(zhuǎn)換為utf-8
舉報(bào)
本教程帶您解開python爬蟲這門神奇技術(shù)的面紗
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2016-03-24
試一下這樣吧
2022-03-25
評(píng)論欄【發(fā)表】的右邊有一個(gè)【課件下載】。id是標(biāo)簽的唯一標(biāo)識(shí),加上是在頁面上是看不到效果的,如果想獲取這個(gè)標(biāo)簽的時(shí)候通過id就很容易找到了
2016-03-26
謝謝你!我的問題解決了,是在<html>后面加上utf-8就好了。非常感謝你!fout.write("<html><meta charset=\"utf-8\" />")
2016-03-24
沒有轉(zhuǎn)換編碼格式吧,默認(rèn)是標(biāo)準(zhǔn)編碼,需要轉(zhuǎn)換為utf-8