芯片價格漲價,如何及時查詢庫存
由于疫情影響,導致物流、原料、人工等成本大幅增加,部分芯片原廠停產、減產,導致芯片出廠價上調。另外一部分芯片經(jīng)銷商人為囤貨或故意抬高價格導致芯片價格****一路上漲。如果可以及時跟蹤各芯片廠家的官網(wǎng)或交易平臺,實時關注庫存情況及時下單,可以減少中間環(huán)節(jié),降低采購成本。通過爬蟲代理實現(xiàn)多并發(fā)、低延遲的網(wǎng)絡請求,及時分析海量商品動態(tài),可以滿足芯片業(yè)務要求,示例如下:
#! -*- 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) # 要訪問的目標頁面 targetUrlList = [ "https://www.ti.com", "https://www.1688.com/", ] # 代理服務器(產品官網(wǎng) www.16yun.cn) proxyHost = "t.16yun.cn" proxyPort = "31111" # 代理驗證信息 proxyUser = "username" proxyPass = "password" proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % { "host": proxyHost, "port": proxyPort, "user": proxyUser, "pass": proxyPass, } # 設置 http和https訪問都是用HTTP代理 proxies = { "http": proxyMeta, "https": proxyMeta, } # 設置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標志,均能夠保持相同的外網(wǎng)IP for i in range(3): for url in targetUrlList: r = urllib2.Request(url) print(urllib2.urlopen(r).read())
*博客內容為網(wǎng)友個人發(fā)布,僅代表博主個人觀點,如有侵權請聯(lián)系工作人員刪除。