请教各位大神,我要怎么爬出这个网页html中灰色部分最后的2.1610这个数字?
并且我有一系列和这个网页具有高度相似html的网页,我想要爬出同样位置的这一串数字,我应该如何利用beautifulsoup完成我的代码?
现我的代码如下(注释部分采用了第一位回答者的代码):
def getLinks(articleUrl):
html=urlopen(articleUrl)
#s = '<tr><td><b><a href=".././statistics/power" title="Exponent of the power-law degree distibution">Power law exponent (estimated) with d<sub>min</sub></a></b></td><td>2.1610(d<sub>min</sub> = 2) </td></tr>'
#soup = BeautifulSoup(s, 'html.parser')
#print(soup.find_all('td')[1].contents[0][:-2])
Python 的网页解析一般有以下方法:
1.字符串方法
2.正则表达式
3.html/xml文本解析库的调用(如著名的BeautifulSoup库)
对于你所给的例子, 假设:
由于文本特征非常明显, 可以这样处理:
1.字符串处理方法:
2.re:
3.BeautifulSoup:
以上方法均是根据给定的例子临时设计的.