【发布时间】:2021-09-17 22:42:11
【问题描述】:
我正在尝试从使用 urllib.request 获得的 HTML 页面的副本中提取一个数字
我在正则表达式中尝试了几种不同的模式,但没有得到任何输出,所以我显然没有正确格式化模式,但无法让它工作
下面是我在字符串中的一小部分 HTML
</ul>\n \n <p>* * * * *</p>\n -->\n \n <b>DistroWatch database summary</b><br/>\n <ul>\n <li>Number of <a href="search.php?status=All">all distributions</a> in the database: 926<br/>\n <li>Number of <a href="search.php?status=Active">
我试图从字符串中取出 926,我的代码在下面,我不知道我做错了什么
import urllib.request
import re
page = urllib.request.urlopen('http://distrowatch.com/weekly.php?issue=current')
#print(page.read())
print(page.read())
pageString = str(page.read())
#print(pageString)
DistroCount = re.search('^all distributions</a> in the database: ....<br/>\n$', pageString)
print(DistroCount)
任何帮助、指针或资源建议将不胜感激
【问题讨论】:
-
试试这个:
all distributions</a> in the database: (\d{3})<br/>和print(DistroCount.group(1))