这篇文章主要介绍了 python 使用 htmllib 分析网页内容的方法, 涉及 Python 使用 htmllib 模块的相关技巧, 需要的朋友可以参考下
本文实例讲述了 python 使用 htmllib 分析网页内容的方法分享给大家供大家参考具体实现方法如下:
- 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 程序设计有所帮助
来源: https://www.php1.cn/detail/php-cd25dfe178.html