Python基础 HTMLParser
来源:互联网 发布:qt tcp编程 编辑:程序博客网 时间:2024/05/21 07:48
解析该HTML页面
编写一个搜索引擎
1. 第一步是用爬虫把目标网站的页面抓下来
2. 第二步就是解析该HTML页面
运行示例
#!/usr/bin/env python3# -*- coding: utf-8 -*-# Python基础 HTMLParserdata ='''<html> <head> <!-- head --> </head> <body> <!-- test html parser --> </body></html>'''from html.parser import HTMLParserfrom html.entities import name2codepointclass MyHTMLParser(HTMLParser): def handle_starttag(self, tag, attrs): print('<%s>' % tag) def handle_endtag(self, tag): print('</%s>' % tag) def handle_startendtag(self, tag, attrs): print('<%s/>' % tag) def handle_data(self, data): print(data) def handle_comment(self, data): print(' <!--', data, '-->') def handle_entityref(self, name): print('&%s;' % name) def handle_charref(self, name): print('&#%s;' % name)parser = MyHTMLParser()parser.feed(data)
运行结果
D:\PythonProject>python main.py<html><head> <!-- head --></head><body> <!-- test html parser --></body></html>
阅读全文
0 0
- Python基础 HTMLParser
- python网络爬虫基础(利用HTMLParser)
- python HTMLParser
- python 解析html基础 HTMLParser库,方法,及代码实例
- htmlparser 基础 网页拔取
- Python使用HTMLParser.HTMLParser处理网页
- python模块之HTMLParser
- Python之HTMLParser
- python内置HTMLParser模块
- python模块之HTMLParser
- python模块之HTMLParser
- HTMLParser python usage
- python之htmlParser入门教程
- python的HTMLParser
- python HTMLParser 库 笔记
- Python——HTMLParser
- python爬虫之HTMLParser
- HtmlParser基础入门-文本抽取
- .NET Framework 自动内存管理机制深入剖析 (C#分析篇)
- Anaconda3 5.0.1 无法启动spyder, jupyter notebook
- 疯狂Activiti6.0连载(28)BPMN补偿中间事件
- 487-3279(poj 1002)
- 实时计算框架storm基础
- Python基础 HTMLParser
- 数据结构课程设计——学生信息管理系统
- iOS 音视频之mp3播放
- Android7.0去电流程源码分析(一)
- Python 决策树 泰坦尼克号乘客是否生还决策模型
- spring概述之快速入门
- MySQL常用基本SQL语句总结
- Vue学习之computed
- git