国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

python抓取京東價(jià)格分析京東商品價(jià)格走勢(shì)

2020-02-23 05:02:38
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

代碼如下:
from creepy import Crawler
from BeautifulSoup import BeautifulSoup
import urllib2
import json

class MyCrawler(Crawler):
    def process_document(self, doc):
        if doc.status == 200:
            print '[%d] %s' % (doc.status, doc.url)
            try:
                soup = BeautifulSoup(doc.text.decode('gb18030').encode('utf-8'))
            except Exception as e:
                print e
                soup = BeautifulSoup(doc.text)
            print soup.find(id="product-intro").div.h1.text
            url_id=urllib2.unquote(doc.url).decode('utf8').split('/')[-1].split('.')[0]
            f = urllib2.urlopen('http://p.3.cn/prices/get?skuid=J_'+url_id,timeout=5)
            price=json.loads(f.read())
            f.close()
            print price[0]['p']
        else:
            pass

crawler = MyCrawler()
crawler.set_follow_mode(Crawler.F_SAME_HOST)
crawler.set_concurrency_level(16)
crawler.add_url_filter('/.(jpg|jpeg|gif|png|js|css|swf)$')
crawler.crawl('http://item.jd.com/982040.html')

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 华阴市| 天全县| 徐闻县| 辽宁省| 临武县| 怀来县| 太保市| 儋州市| 鹤庆县| 饶阳县| 张北县| 石河子市| 滨海县| 中方县| 铜山县| 阿拉善左旗| 林口县| 阿巴嘎旗| 七台河市| 衡水市| 榆林市| 武陟县| 太仆寺旗| 十堰市| 精河县| 奉化市| 岑溪市| 临洮县| 南京市| 民县| 乐至县| 枞阳县| 唐海县| 鄂温| 油尖旺区| 盈江县| 徐闻县| 晋宁县| 元氏县| 昌乐县| 揭东县|