python抓取京東價格分析京東商品價格走勢
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')
相關(guān)文章
如何使用Python實現(xiàn)數(shù)據(jù)透視表、音頻文件格式轉(zhuǎn)換
這篇文章主要介紹了用Python實現(xiàn)數(shù)據(jù)透視表、音頻文件格式轉(zhuǎn)換,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-10-10Python之ThreadPoolExecutor線程池問題
這篇文章主要介紹了Python之ThreadPoolExecutor線程池問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-03-03python讀取excel數(shù)據(jù)并且畫圖的實現(xiàn)示例
這篇文章主要介紹了python讀取excel數(shù)據(jù)并且畫圖的實現(xiàn)示例,幫助大家更好的理解和使用python,感興趣的朋友可以了解下2021-02-02Python?functools凍結(jié)參數(shù)小技巧實現(xiàn)代碼簡潔優(yōu)化
這篇文章主要為大家介紹了Python?functools凍結(jié)參數(shù)小技巧實現(xiàn)代碼簡潔優(yōu)化示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-12-12Python常用標準庫詳解(pickle序列化和JSON序列化)
這篇文章主要介紹了Python常用標準庫,主要包括pickle序列化和JSON序列化模塊,通過使用場景分析給大家介紹的非常詳細,需要的朋友可以參考下2022-05-05關(guān)于TensorFlow新舊版本函數(shù)接口變化詳解
今天小編就為大家分享一篇關(guān)于TensorFlow新舊版本函數(shù)接口變化詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-02-02