国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 禹州市| 外汇| 五大连池市| 青岛市| 全南县| 临高县| 浦城县| 和平区| 芦山县| 巴马| 邢台县| 四平市| 惠安县| 唐河县| 甘孜县| 通江县| 来凤县| 九江市| 东城区| 禄劝| 云龙县| 佳木斯市| 大渡口区| 永兴县| 延吉市| 西青区| 来安县| 白水县| 宁化县| 古丈县| 沅陵县| 漳州市| 集贤县| 乐平市| 桦川县| 柯坪县| 时尚| 宾阳县| 锦州市| 宁陕县| 长兴县|