[Python] 利用Selenium寫一個在蝦皮上搶咖啡豆的腳本
[前情提要]
自從2022年2月入手沖咖啡坑之後,想要把眾多網友推薦的咖啡豆店家都買一輪試試看
其中有一家特別被咖啡有推崇的厲(囂)害(張)的店家,豆子都要在蝦皮上用搶的…
大概嘗試了3次手速不如人皆失敗收場,於是發揮工程師精神利用程式幫我搶XD
我們來看看以下網友的說法:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
店家的規則如下…
OK,開始動手寫程式 (Python、Selenium、Chromedriver安裝直接忽略)
最一開始寫的程式,會遇到一個問題…
就是使用Chromedriver開起的Chromedriver瀏覽器,會是一個全新的乾淨瀏覽器(沒有任何紀錄和GOOGLE帳號登入)
原本第一版程式碼,是會進入蝦皮的登入畫面輸入帳密
但遇到了蝦皮2FA認證直接快不起來,保證搶不到QQ
最快的方式就是操作我們已經登入進蝦皮網站的Chrome瀏覽器視窗
(並且已經把你的取貨地址、收件人等資訊先設定好)
事前準備設定步驟:
- 打開CMD,CD到Chrome瀏覽器的安裝路徑(通常為C:\Program Files (x86)\Google\Chrome\Application),執行以下指令
這句指令是啟動 Chrome瀏覽器的除錯模式,user-data-dir=“D:\selenium\AutomationProfile” 是在單獨的組態檔中啟動Chrome瀏覽器,可以當作是一個新的瀏覽器,埠號可自行指定。
- 登入你的蝦皮帳號,清空你的購物車,設定好7-11貨到付款要寄的店家、收件人資訊。
程式碼的部分十分簡單,以下就是全部了…
GitHub連結:
https://github.com/mko123654/shopeeScript
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
我們所要做的只有在開賣前幾分鐘點開程式,擺著,等程式偵測開賣後自動執行XD
沒意外的話,一定搶得到喔!!