Python Regex-解析HTML [英] Python Regex - Parsing HTML

查看:49
本文介绍了Python Regex-解析HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码,它给了我AttributeError:'NoneType'对象没有属性'group'.

I have this little code and it's giving me AttributeError: 'NoneType' object has no attribute 'group'.

import sys
import re

#def extract_names(filename):

f = open('name.html', 'r')
text = f.read()

match = re.search (r'<hgroup><h1>(\w+)</h1>', text)
second = re.search (r'<li class="hover">Employees: <b>(\d+,\d+)</b></li>', text)  

outf = open('details.txt', 'a')
outf.write(match)
outf.close()

我的意图是读取一个.HTML文件,以查找< h1> 标记值和员工人数,并将其附加到文件中.但是由于某种原因,我似乎无法正确处理.非常感谢您的帮助.

My intention is to read a .HTML file looking for the <h1> tag value and the number of employees and append them to a file. But for some reason I can't seem to get it right. Your help is greatly appreciated.

推荐答案

仅出于完成目的:您的错误消息仅表明您的正则表达式失败,并且未返回任何内容...

Just for the sake of completion: your error message just indicate that your regular expression failed and did not return anything...

这篇关于Python Regex-解析HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆