码迷,mamicode.com
首页 > 编程语言 > 详细

python解析远程web页面的代码

时间:2019-06-12 18:05:06      阅读:100      评论:0      收藏:0      [点我收藏+]

标签:index   python   feed   parser   htm   read   bst   parse   formatter   

把写代码过程中经常用到的一些代码段珍藏起来,下面的代码段是关于python解析远程web页面的代码。

import htmllib, urllib, formatter, sys

def parse(url, formatter):
    f = urllib.urlopen(url)
    data = f.read()
    f.close()
    p = htmllib.HTMLParser(formatter)
    p.feed(data)
    p.close()

fmt = formatter.AbstractFormatter(formatter.DumbWriter(sys.stdout))
parse("index.htm", fmt)

python解析远程web页面的代码

标签:index   python   feed   parser   htm   read   bst   parse   formatter   

原文地址:https://blog.51cto.com/14392820/2407785

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!