URL
获取URL参数中的数字
import reurl = 'https://www.amazon.com/sports-outdoors/b/ref=dp_bc_aui_C_1?ie=UTF8&node=3375251't = re.findall('node=(\d+)', url)[0]
获取价格字符串的数值
import re# price='$1,000.3'# price='2.000,3€'price='¥50.3'a = str.replace(price, ',', '.')price = re.findall('([\d,.]+)[,.](\d+)$', a)if len(price): price = price[0] price = '.'.join(price) price = float(price)
获取亚马逊评分
# star = '0 out of 5'star = '1.4 out of 5'# star = '5 out of 5'star = str.replace(star, ',', '.')t = re.findall('(\d+[,.]*\d*)', star)star = float(min(t))