python 解析html标签中的属性
来源:互联网 发布:数据库模型图是什么 编辑:程序博客网 时间:2024/05/24 02:26
#!/usr/bin/pythonfrom lxml import etreefrom io import StringIO, BytesIOfrom HTMLParser import HTMLParserfrom lxml import html if __name__ == '__main__': # print(type(data)) data ={u'seatbid': [{u'bid': [{u'nurl': u'http://baidu.com', u'cid': u'986191', u'crid': u'4581591', u'price': 0.1317348624101392, u'adid': u'56cb0b8b70f8f8100805eeda', u'adomain': [u'mobvista.com'], u'adm': u'<a href="http://52.0.105.35/0.jpg" width ="320" height ="50" /> <html> <body><script type=\'text/javascript\'> var ifr = document.createElement(\'iframe\'); ifr.style.display = \'none\'; ifr.src = \'http://beijing.com?a=1&appname=test\'; document.body.appendChild(ifr); </script> </body></html></a> ', u'id': u'222'}]}], u'id': u'bid1-7'} admstr = data['seatbid'][0]['bid'][0]['adm'] tree = html.fromstring(admstr) # print [e.text_content() for e in tree.xpath("//a")] // result is ok parser = etree.HTMLParser() tree = etree.parse(StringIO(admstr), parser) ahref = [a.attrib['href'] for a in tree.xpath("//a")] imghref=[img.attrib['src'] for img in tree.xpath("//img")] print "ahref is :",ahref[0] print "imghref is :",imghref[0]
0 0
- python 解析html标签中的属性
- python 正则表达式过滤文本中的html标签 源代码解析
- html标签及其中的属性
- html---标签中的target属性
- html标签中的lang属性
- HTML基础标签属性详细解析
- HTML基础标签属性详细解析
- html meta标签属性用法解析
- Java解析Html自定义标签的属性
- html中的input标签的checked属性
- HTML中的form标签的enctype 属性
- HTML中的标签textarea的属性…
- JQUERY 获取html标签中的属性值
- HTML中的标签、元素、属性和值
- python 解析html中的link
- jsoup解析html中的<select>标签
- jstl中的for each标签属性解析
- python 获取html标签中的值
- python-pexpect模块的使用(ssh服务器 自动登录批量执行scp)
- 编译android源码7---android 源码目录结构
- Android多线程断点续传下载Demo
- React Native学习笔记-2:this.props.navigator undefined
- iOS创建系统TabBar
- python 解析html标签中的属性
- 关于xcode7 ios9的一些变化
- 安卓开发:WebView下载文件
- NDK开发简单流程
- JAVA操作Excel文件
- swift-集合类型01-数组的基本操作
- spring是怎么知道哪个方法或者类上有@requestMapping这个注解
- SMC计算节点重刷系统步骤
- hashMap源码分析