我正在尝试一种代码,它将使用Beautiful Soup从URL中提取数字,然后求和这些数字的总和,但我一直得到一个错误,如下所示:
Expected string or buffer
我认为这和正则表达式有关,但我不能指出问题所在。在
import re
import urllib
from BeautifulSoup import *
htm1 = urllib.urlopen('https://pr4e.dr-chuck.com/tsugi/mod/python-data/data/comments_42.html').read()
soup = BeautifulSoup(htm1)
tags = soup('span')
for tag in tags:
y = re.findall ('([0-9]+)',tag.txt)
print sum(y)
我建议使用}(这是旧版本)。您还需要更改以下行:
bs4
而不是{像这样的事情:
^{pr2}$看看这是否能让你走得更远:
相关问题 更多 >
编程相关推荐