這篇文章主要介紹了python使用htmllib分析網(wǎng)頁內(nèi)容的方法,涉及Python使用htmllib模塊的相關(guān)技巧,需要的朋友可以參考下
本文實例講述了python使用htmllib分析網(wǎng)頁內(nèi)容的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
- import htmllib, urllib, formatter, sys
- website = urllib.urlopen("http://yourweb.com")
- data = website.read()
- website.close()
- format = formatter.AbstractFormatter(formatter.DumbWriter(sys.stdout))
- ptext = htmllib.HTMLParser(format)
- ptext.feed(data)
- ptext.close()
希望本文所述對大家的Python程序設(shè)計有所幫助。
新聞熱點
疑難解答
圖片精選