URL

获取URL参数中的数字

  1. import re
  2. url = 'https://www.amazon.com/sports-outdoors/b/ref=dp_bc_aui_C_1?ie=UTF8&node=3375251'
  3. t = re.findall('node=(\d+)', url)[0]

获取价格字符串的数值

  1. import re
  2. # price='$1,000.3'
  3. # price='2.000,3€'
  4. price='¥50.3'
  5. a = str.replace(price, ',', '.')
  6. price = re.findall('([\d,.]+)[,.](\d+)$', a)
  7. if len(price):
  8. price = price[0]
  9. price = '.'.join(price)
  10. price = float(price)

获取亚马逊评分

  1. # star = '0 out of 5'
  2. star = '1.4 out of 5'
  3. # star = '5 out of 5'
  4. star = str.replace(star, ',', '.')
  5. t = re.findall('(\d+[,.]*\d*)', star)
  6. star = float(min(t))