因为只是初学,所以没有借助beautiful soup4和Scrapy这些库,只用到了re与urllib这两个内置库和一些built-in functions
以下内容学自网络
方法一:通过京东移动商城(因为它没有把价格藏在js中)
# codeing=utf-8
import urllib.request
import re
#通过京东移动接口
url = 'http://item.jd.com/997951.html'#原本的网址
jdid = re.search(r'/(\d+)\.html',url).group(1)#原本的网址提取出商品ID,即997951
url = 'http://m.jd.com/product/'+str(jdid)+'.html'#转换成为移动商城的url
html = urllib.request.urlopen(url).read().decode('utf-8')#通过对源代码进行utf-8解码
aa = re.findall(r'<font color="red" style="font-family:Arial;font-weight:bold;font-size:18px">&.*</font>', html)[0]#这里使用的是findall,可以用别的
aa = re.findall(r'\d+\.\d+&