芯片價(jià)格漲價(jià),如何及時(shí)查詢庫存
由于疫情影響,導(dǎo)致物流、原料、人工等成本大幅增加,部分芯片原廠停產(chǎn)、減產(chǎn),導(dǎo)致芯片出廠價(jià)上調(diào)。另外一部分芯片經(jīng)銷商人為囤貨或故意抬高價(jià)格導(dǎo)致芯片價(jià)格****一路上漲。如果可以及時(shí)跟蹤各芯片廠家的官網(wǎng)或交易平臺(tái),實(shí)時(shí)關(guān)注庫存情況及時(shí)下單,可以減少中間環(huán)節(jié),降低采購成本。通過爬蟲代理實(shí)現(xiàn)多并發(fā)、低延遲的網(wǎng)絡(luò)請(qǐng)求,及時(shí)分析海量商品動(dòng)態(tài),可以滿足芯片業(yè)務(wù)要求,示例如下:
#! -*- encoding:utf-8 -*- import urllib2 import random import httplib class HTTPSConnection(httplib.HTTPSConnection): def set_tunnel(self, host, port=None, headers=None): httplib.HTTPSConnection.set_tunnel(self, host, port, headers) if hasattr(self, 'proxy_tunnel'): self._tunnel_headers['Proxy-Tunnel'] = self.proxy_tunnel class HTTPSHandler(urllib2.HTTPSHandler): def https_open(self, req): return urllib2.HTTPSHandler.do_open(self, HTTPSConnection, req, context=self._context) # 要訪問的目標(biāo)頁面 targetUrlList = [ "https://www.ti.com", "https://www.1688.com/", ] # 代理服務(wù)器(產(chǎn)品官網(wǎng) www.16yun.cn) proxyHost = "t.16yun.cn" proxyPort = "31111" # 代理驗(yàn)證信息 proxyUser = "username" proxyPass = "password" proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % { "host": proxyHost, "port": proxyPort, "user": proxyUser, "pass": proxyPass, } # 設(shè)置 http和https訪問都是用HTTP代理 proxies = { "http": proxyMeta, "https": proxyMeta, } # 設(shè)置IP切換頭 tunnel = random.randint(1, 10000) headers = {"Proxy-Tunnel": str(tunnel)} HTTPSConnection.proxy_tunnel = tunnel proxy = urllib2.ProxyHandler(proxies) opener = urllib2.build_opener(proxy, HTTPSHandler) urllib2.install_opener(opener) # 訪問三次網(wǎng)站,使用相同的tunnel標(biāo)志,均能夠保持相同的外網(wǎng)IP for i in range(3): for url in targetUrlList: r = urllib2.Request(url) print(urllib2.urlopen(r).read())
*博客內(nèi)容為網(wǎng)友個(gè)人發(fā)布,僅代表博主個(gè)人觀點(diǎn),如有侵權(quán)請(qǐng)聯(lián)系工作人員刪除。