我正在尝试使用urllib来抓取html页面,然后使用beautifulsoup来提取数据。我想从comments_42.html中获取所有数字并打印出它们的总和,然后显示数据的数量。 这是我的代码,我正在尝试使用正则表达式,但它不适用于我。从使用Python中的beautifulsoup的网站中提取数字
import urllib
from bs4 import BeautifulSoup
url = 'http://python-data.dr-chuck.net/comments_42.html'
html = urllib.urlopen(url).read()
soup = BeautifulSoup(html,"html.parser")
tags = soup('span')
for tag in tags:
print tag
1.您没有使用正则表达式,只要我能看到; 2. *“不起作用”的意思是什么? – jonrsharpe
我的意思是我在使用正则表达式时得到了堆栈,这可能是由于我的编程技巧低下造成的。 – Salosha
那么?这不是教程服务。 *试一试。* – jonrsharpe