收集到很多易迅网的商品ID,于是想把这些ID对应的商品信息爬下来。通过简单分析发现,易迅网的各类信息都是直接放在HTML页面上,所以,解析一个页面就好了。
最后返回每个ID对应的商品url,标题,易迅价,促销价,类目 。
下面是python代码:
#!/usr/bin/env python
#coding:utf-8
'''
Created on 2015年03月11日
@author: zhaohf
'''
import urllib2
from bs4 import BeautifulSoup
def get_yixun(id):
price_origin,price_sale,category = '0','0',''
url = 'http://item.yixun.com/item-' + id + '.html'
html = urllib2.urlopen(url).read().decode('utf-8')
soup = BeautifulSoup(html)
title = unicode(soup.title.text.strip().strip(u'【价格_报价_图片_行情】-易迅网').replace(u'】','')).encode('utf-8').decode('utf-8')
try:
soup_origin = soup.find("dl", { "class" : "xbase_item xprice xprice_origin" })
price_origin = soup_origin