如何在Python中使用regex解析HTML中的多行。我已经设法使用下面的代码在同一行上串匹配模式。你知道吗
i=0
while i<len(newschoollist):
url = "http://profiles.doe.mass.edu/profiles/general.aspx?topNavId=1&orgcode="+ newschoollist[i] +"&orgtypecode=6&"
htmlfile = urllib.urlopen(url)
htmltext = htmlfile.read()
regex = '>Phone:</td><td>(.+?)</td></tr>'
pattern = re.compile(regex)
value = re.findall(pattern,htmltext)
print newschoollist[i], valuetag, value
i+=1
然而,当我试图识别像这样更复杂的HTML时。。。你知道吗
<td>Attendance Rate</td>
<td class='center'> 90.1</td>
我得到空值。我相信问题出在我的语法上。我已经在google上搜索过regex并阅读了大部分文档,但是我正在寻找这种应用程序的帮助。我希望有人能给我指出正确的方向。是否有(+?)像这样的组合可以帮助我告诉regex跳过一行HTML?你知道吗
我希望findall找到的是90.1 “出勤率 ““
谢谢!你知道吗
最后我用了(soup.get\u文本())效果很好。谢谢!你知道吗
Use an HTML Parser。使用^{} 的示例:
打印(个人资料联系信息):
相关问题 更多 >
编程相关推荐