Python爬蟲(chóng)之定時(shí)搶購(gòu)淘寶商品
?
?
import time from selenium import webdriver import datetime class Spider: def __init__ (self, url): self. __base_url = url self. __headers = { ' User-Agent ' : ' Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36 ' , } def get_url(self): global driver driver.get(self. __base_url ) def login(self): global driver if driver.find_element_by_link_text( " 親,請(qǐng)登錄 " ): driver.find_element_by_link_text( " 親,請(qǐng)登錄 " ).click() print ( " 請(qǐng)?jiān)?0秒內(nèi)掃描登陸 " ) time.sleep( 30 ) driver.get( " https://cart.taobao.com/cart.htm " ) def selectAll(self,method): global driver # 打開(kāi)購(gòu)物車列表頁(yè)面 driver.get( " https://cart.taobao.com/cart.htm " ) time.sleep( 3 ) # 是否全選購(gòu)物車 if method == 0: while True: try : if driver.find_element_by_id( " J_SelectAll1 " ): driver.find_element_by_id( " J_SelectAll1 " ).click() break except : # print(f"找不到購(gòu)買按鈕") pass if method ==1 : print (f " 請(qǐng)手動(dòng)勾選需要購(gòu)買的商品 " ) time.sleep( 30 ) def buy(self,times): global driver while True: now = datetime.datetime.now() # 對(duì)比時(shí)間,時(shí)間到的話就點(diǎn)擊結(jié)算 if now > times: # 點(diǎn)擊結(jié)算按鈕 while True: try : if driver.find_element_by_link_text( " 結(jié) 算 " ): driver.find_element_by_link_text( " 結(jié) 算 " ).click() print (f " 結(jié)算成功,準(zhǔn)備提交訂單 " ) break except : pass # 點(diǎn)擊提交訂單按鈕 while True: try : if driver.find_element_by_link_text( ' 提交訂單 ' ): driver.find_element_by_link_text( ' 提交訂單 ' ).click() print (f " 搶購(gòu)成功,請(qǐng)盡快付款 " ) except : # print(f"再次嘗試提交訂單") pass time.sleep( 0.01 ) option = webdriver.ChromeOptions() option.add_argument( ' disable-infobars ' ) driver = webdriver.Chrome(chrome_options= option) spider = Spider( " https://www.taobao.com " ) spider.get_url() spider.login() # 設(shè)置0為全選、1為手動(dòng) spider.selectAll(0) # 設(shè)置搶購(gòu)時(shí)間 set_time = datetime.datetime(2019,6,6,1,25 ) spider.buy(set_time)
?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
