我正在嘗試使用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