【发布时间】:2013-07-12 01:35:59
【问题描述】:
我正在学习re 和BeautifulSoup 的模块。我对下一个代码的几行有疑问。我不知道group() 的用途以及contents[] 中括号内的内容是什么
from bs4 import BeautifulSoup
import urllib2
import re
url = 'http://www.ebay.es/itm/LOTE-5-BOTES-CERVEZAARGUS-SET-5-BEER-CANSLOT-5-CANETTES-BIRES-LATTINE-BIRRA-/321162173293' #raw_input('URL: ')
code = urllib2.urlopen(url).read();
soup = BeautifulSoup(code)
tag = soup.find('span', id='v4-27').contents[0]
price_string = re.search('(\d+,\d+)', tag).group(1)
precio_final = float(price_string.replace(',' , '.'))
print precio_final
【问题讨论】:
-
您可以从他们的文档中轻松获得积分。 BeautifulSoup 和 re.
标签: python regex beautifulsoup