Beautiful SoupでPythonのhtml解析でxmlをテキストに変換する理想的な方法は何ですか?Beautiful SoupでPythonのhtml解析でxmlデータを使用する理想的な方法は何ですか?
私はPython 2.7 BeautifulSoupライブラリを使ってhtml解析を行っていますが、私は「スープ」へのステップに行くことができますが、必要なデータをどのように抽出するかわからないので、
次の例では、スパンタグ内のすべての数値を抽出して追加します。より良い方法がありますか?
XMLデータ: http://python-data.dr-chuck.net/comments_324255.html
CODE:
import urllib2
from BeautifulSoup import *
import re
url = 'http://python-data.dr-chuck.net/comments_324255.html'
html = urllib2.urlopen(url).read()
soup = BeautifulSoup(html)
spans = soup('span')
lis = list()
span_str = str(spans)
sp = re.findall('([0-9]+)', span_str)
count = 0
for i in sp:
count = count + int(i)
print('Sum:', count)
もっと読むBeautifulSoup doc - 多くの便利な機能があります。 – furas