通过urllib2抓取HTML网页,然后过滤出包含特定字符的行,并写入Excel文件: # -*- coding: utf-8 -*- import sys #import urllib import urllib2 from xlwt import Workbook def getdata(keywords, line): date = '' if keywords in line: # 本行包含keywords start = line.find('>',) end = line.find(…