課程
/后端開發(fā)
/Python
/Python開發(fā)簡單爬蟲
為什么我可以運(yùn)行,但是瀏覽器中不顯示內(nèi)容
2016-05-14
源自:Python開發(fā)簡單爬蟲 8-1
正在回答
你可以看看生成的html文件內(nèi)容格式對不對啊
# coding:utf8
class HtmlOutputer(object):
? ??
? ? def __init__(self):
? ? ? ? self.datas = []
? ? def collect_data(self,data):
? ? ? ? if data is None:
? ? ? ? ? ? return
? ? ? ? self.datas.append(data)
? ? def output_html(self):
? ? ? ? fout = open('output.html','w')
? ? ? ??
? ? ? ? fout.write("<html>")
? ? ? ? fout.write("<body>")
? ? ? ? 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'].encode('utf-8'))
? ? ? ? ? ? fout.write("<td>%s</td>" % data['summary'].encode('utf-8'))
? ? ? ? ? ? fout.write("</tr>")
? ? ? ? fout.write("</table>")
? ? ? ? fout.write("</body>")
? ? ? ? fout.write("</html>")
? ? ? ? fout.close()
也是輸出只有代碼,沒有爬取的內(nèi)容,求賜教
亂碼怎么破?
qq_岳怒扇_0
舉報(bào)
本教程帶您解開python爬蟲這門神奇技術(shù)的面紗
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2016-05-15
你可以看看生成的html文件內(nèi)容格式對不對啊
2016-07-04
# coding:utf8
class HtmlOutputer(object):
? ??
? ? def __init__(self):
? ? ? ? self.datas = []
? ??
? ? def collect_data(self,data):
? ? ? ? if data is None:
? ? ? ? ? ? return
? ? ? ? self.datas.append(data)
? ??
? ? def output_html(self):
? ? ? ? fout = open('output.html','w')
? ? ? ??
? ? ? ? fout.write("<html>")
? ? ? ? fout.write("<body>")
? ? ? ? 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'].encode('utf-8'))
? ? ? ? ? ? fout.write("<td>%s</td>" % data['summary'].encode('utf-8'))
? ? ? ? ? ? fout.write("</tr>")
? ? ? ??
? ? ? ? fout.write("</table>")
? ? ? ? fout.write("</body>")
? ? ? ? fout.write("</html>")
? ? ? ??
? ? ? ? fout.close()
? ? ? ??
也是輸出只有代碼,沒有爬取的內(nèi)容,求賜教
2016-05-16
亂碼怎么破?