在看廖雪峰老师的Python教程,常见内置模块 HTMLParser:
http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/001407500818913cef22f247dbd4699921fe9d309727a20000
作业:找一个网页,例如https://www.python.org/events/python-events/,用浏览器查看源码并复制,然后尝试解析一下HTML,输出Python官网发布的会议时间、名称和地点。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2017-06-01 09:08:30
# @Author : kk (zwk.patrick@foxmail.com)
# @Link : blog.csdn.net/PatrickZheng
import HTMLParser, urllib
class MyHTMLParser(HTMLParser.HTMLParser):
def __init__(self):
HTMLParser.HTMLParser.__init__(self)
self._title = [False]
self._time =[False]
self._place = [False]
self.time = '' # 用于拼接时间
def