主頁 > 知識庫 > 用pushplus+python監(jiān)控亞馬遜到貨動態(tài)推送微信

用pushplus+python監(jiān)控亞馬遜到貨動態(tài)推送微信

熱門標(biāo)簽:400電話在線如何申請 江門智能電話機(jī)器人 智能電話機(jī)器人調(diào)研 滴滴地圖標(biāo)注公司 甘肅高頻外呼系統(tǒng) 地圖標(biāo)注可以遠(yuǎn)程操作嗎 天津塘沽區(qū)地圖標(biāo)注 杭州房產(chǎn)地圖標(biāo)注 如何申請400電話代理

xbox series和ps5發(fā)售以來,國內(nèi)黃牛價(jià)格一直居高不下。雖然海外amazon上ps5補(bǔ)貨很少而且基本撐不過一分鐘,但是xbox series系列明顯要好搶很多。

日亞、德亞的xbox series x/s都可以直郵中國大陸,所以我們只需要借助腳本,監(jiān)控相關(guān)網(wǎng)頁的動態(tài),在補(bǔ)貨的第一時(shí)刻通過微信告知我們,然后迅速人工購買即可!

需求:pushplus(需要微信關(guān)注公眾號)、python3

一、pushplus相關(guān)介紹

pushplus提供了免費(fèi)的微信消息推送api,具體內(nèi)容可以參考他的官網(wǎng):pushplus(推送加)微信推送消息直達(dá) (hxtrip.com)

我們需要用到的東西有,登陸后的個(gè)人Token(用于精準(zhǔn)推送消息),如圖:

調(diào)用該接口可使用如下代碼,token為上面提到的你個(gè)人的token,titile對應(yīng)推送標(biāo)題,content對應(yīng)推送內(nèi)容,此代碼借鑒了官方demo

def post_push(token, title, content):
 url = 'http://pushplus.hxtrip.com/send'
 data = {
  "token": token,
  "title": title,
  "content": content
 }
 body = json.dumps(data).encode(encoding='utf-8')
 headers = {'Content-Type': 'application/json'}
 requests.post(url, data=body, headers=headers)

二、整體思路

不出意外的話,你在編寫代碼時(shí),amazon應(yīng)該處于無貨狀態(tài)(有貨直接就買了啊喂)?。?!我們在此時(shí)打開amazon頁面,可以看到如下界面:

在新版Edge瀏覽器或者chrome下,按F12查看網(wǎng)頁源碼,選定中間Currently unavailable標(biāo)識的區(qū)域(五顆星下面那個(gè),最好覆蓋范圍大一點(diǎn)),能看到代碼如下:

有一個(gè)比較簡單的辦法,判斷amazon是否有補(bǔ)貨。我們可以抓取這一部分的html源碼,存進(jìn)一個(gè)文件里(txt即可)。每過一定時(shí)間,重新抓取源碼,如果這些源碼變化了,那么基本上是網(wǎng)站更新了(補(bǔ)貨了)。不過有個(gè)小瑕疵,這種補(bǔ)貨也可能是亞馬遜第三方(黃牛)補(bǔ)貨-  -

不過總歸是有了一個(gè)判斷上新的方法嘛;其實(shí)黃牛補(bǔ)貨很少的,德亞上好像看不到黃牛(我個(gè)人沒見過德亞上的第三方賣xsx的),日亞上基本沒有啥黃牛賣xbox

好了,接下來,我們看看如何實(shí)現(xiàn)相關(guān)功能

三、Requests+BeautifulSoup獲取相關(guān)html源碼

我們使用Requests+BeautfifulSoup來抓取div id = 'availability_feature_div>  /div>這個(gè)標(biāo)簽內(nèi)部的所有html源碼

headers = {
   "User-Agent": "Mozilla/5.0 (Linux; Android 9; SM-A102U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.93 Mobile Safari/537.36",
   'Content-Type': 'application/json'
  }
html = requests.get(url=self.url, headers=headers)
soup = BeautifulSoup(html.text, 'lxml')
html.close()
target = str(soup.find('div', id='availability_feature_div'))

注意如果不加headers的話,amazon會檢測到爬蟲,不會給你返回完整html代碼。第7行把requests給close掉是因?yàn)?,我在監(jiān)測時(shí)開了兩個(gè)線程同時(shí)檢測日亞和德亞,如果不加這一句的話,會被amazon認(rèn)為是我在攻擊網(wǎng)站,會拒絕我的網(wǎng)絡(luò)訪問

最終的target是被轉(zhuǎn)為str格式的相應(yīng)html源碼,接下來只需要將其保存到文件,每隔一定時(shí)間再次爬蟲比對就行了

 四、完整代碼

import json
import requests
from bs4 import BeautifulSoup
import filecmp
import time
import threading


class listenThread(threading.Thread):
 def __init__(self, url, originFile, newFile, content):
  threading.Thread.__init__(self)
  self.url = url
  self.originFile = originFile
  self.newFile = newFile
  self.content = content

 def listen(self):
  headers = {
   "User-Agent": "Mozilla/5.0 (Linux; Android 9; SM-A102U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.93 Mobile Safari/537.36",
   'Content-Type': 'application/json'
  }
  html = requests.get(url=self.url, headers=headers)
  soup = BeautifulSoup(html.text, 'lxml')
  html.close()
  target = str(soup.find('div', id='availability_feature_div'))
  filetxt = open(self.originFile, 'w', encoding='utf-8')
  filetxt.write(target)
  filetxt.close()
  while True:
   target = str(soup.find('div', id='availability_feature_div'))
   filetxt = open(self.newFile, 'w', encoding='utf-8')
   filetxt.write(target)
   filetxt.close()
   if filecmp.cmp(self.originFile, self.newFile) == False:
    post_push('這里輸你自己的token', 'xbox update', self.content)
    fileAvail = open(self.originFile, 'w')
    fileAvail.write(target)
    fileAvail.close()
   time.sleep(30)
 def run(self):
  self.listen()


def post_push(token, title, content):
 url = 'http://pushplus.hxtrip.com/send'
 data = {
  "token": token,
  "title": title,
  "content": content
 }
 body = json.dumps(data).encode(encoding='utf-8')
 headers = {'Content-Type': 'application/json'}
 requests.post(url, data=body, headers=headers)


if __name__ == '__main__':
 detect_url = 'https://www.amazon.co.jp/-/en/dp/B08GGKZ34Z/ref=sr_1_2?dchild=1keywords=xboxqid=1611674118sr=8-2'
 #url_special = 'https://www.amazon.co.jp/-/en/dp/B08GG17K5G/ref=sr_1_6?dchild=1keywords=xbox%E3%82%B7%E3%83%AA%E3%83%BC%E3%82%BAxqid=1611722050sr=8-6'
 url_germany = 'https://www.amazon.de/Microsoft-RRT-00009-Xbox-Series-1TB/dp/B08H93ZRLL/ref=sr_1_2?__mk_de_DE=%C3%85M%C3%85%C5%BD%C3%95%C3%91dchild=1keywords=xboxqid=1611742161sr=8-2'
 xbox = listenThread(url=detect_url,originFile='avail.txt',newFile='avail_now.txt',content='日亞')
 #xbox_sp = listenThread(url=detect_url,originFile='avail_sp.txt',newFile='avail_now_sp.txt')
 xbox_germany = listenThread(url=url_germany,originFile='avail_sp.txt',newFile='avail_now_sp.txt',content='德亞')
 xbox.start()
 #xbox_sp.start()
 xbox_germany.start()

本代碼開了兩個(gè)線程分別監(jiān)控日亞和德亞的xsx,detect_url是日亞鏈接,url_germany是德亞鏈接;

注意:德亞能夠直接上,日亞如果你上不去自己想辦法(不能說的東西,你懂的)

里面OriginFile和NewFile的文件名可以隨意命名,OriginFile指的是之前爬蟲的html,NewFile是新的爬蟲html,如果內(nèi)容不一樣,就會收到微信消息推送啦

這個(gè)圖只是測試用的,這個(gè)時(shí)刻日亞也沒有真的補(bǔ)貨哈哈哈

以上就是用pushplus+python監(jiān)控亞馬遜到貨動態(tài)推送微信的詳細(xì)內(nèi)容,更多關(guān)于pushplus+python監(jiān)控亞馬遜到貨動態(tài)的資料請關(guān)注腳本之家其它相關(guān)文章!

您可能感興趣的文章:
  • Python實(shí)戰(zhàn)之能監(jiān)控文件變化的神器—看門狗
  • 教你怎么用Python監(jiān)控愉客行車程
  • python使用pynput庫操作、監(jiān)控你的鼠標(biāo)和鍵盤
  • python 自動監(jiān)控最新郵件并讀取的操作
  • 用python監(jiān)控服務(wù)器的cpu,磁盤空間,內(nèi)存,超過郵件報(bào)警
  • 如何基于Python和Flask編寫Prometheus監(jiān)控
  • python中watchdog文件監(jiān)控與檢測上傳功能
  • python 監(jiān)控logcat關(guān)鍵字功能
  • 用Python監(jiān)控NASA TV直播畫面的實(shí)現(xiàn)步驟

標(biāo)簽:臨汾 德宏 廊坊 長春 河池 東莞 漢中 重慶

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《用pushplus+python監(jiān)控亞馬遜到貨動態(tài)推送微信》,本文關(guān)鍵詞  用,pushplus+python,監(jiān)控,亞馬遜,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《用pushplus+python監(jiān)控亞馬遜到貨動態(tài)推送微信》相關(guān)的同類信息!
  • 本頁收集關(guān)于用pushplus+python監(jiān)控亞馬遜到貨動態(tài)推送微信的相關(guān)信息資訊供網(wǎng)民參考!
  • 企业400电话

    智能AI客服机器人
    15000

    在线订购

    合计11份范本:公司章程+合伙协议+出资协议+合作协议+股权转让协议+增资扩股协议+股权激励+股东会决议+董事会决议

    推薦文章