USA秒杀

作者: 戒灵 | 来源:发表于2019-04-08 17:26 被阅读0次
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.action_chains import ActionChains
    
    import time
    import json
    import re
    import requests
    from lxml import etree
    
    def selum_chrome():
    
        driver = webdriver.Chrome("./chromedriver.exe")
        driver.maximize_window()
        driver.get('https://www.amazon.com/international-sales-offers/b/?ie=UTF8&node=15529609011&ref_=nav_navm_intl_deal_btn')
        asin_list = ['B0072IINY8','B002R0DXQE']
        while True:
    
            time.sleep(10)
            cotet_list = driver.find_elements_by_xpath("//div[contains(@id,'100_dealView')]")
            try:
                for cotet in cotet_list:
                    todays_asin = cotet.find_element_by_xpath(".//a[@id='dealTitle']")
                    asin_href = todays_asin.get_attribute('href')
                    asin = re.findall(r'/dp/(.*?)/ref', asin_href)
                    if asin:
                        if asin[0] in asin_list:
                            cotet.find_element_by_xpath(".//button[contains(@class,'a-button-text')]").click()
                            print('商品'+asin[0]+'加入购物车')
                    else:
                        pass
            except:
                print('异常')
    
    
            try:
                elSlider = driver.find_element_by_xpath("//div[contains(@class,'a-text-center') and not(contains(@class,'hidden'))]/ul/li[contains(@class,'a-last')]/a")
                ActionChains(driver).move_to_element_with_offset(elSlider, 1, 1).click_and_hold().perform()
                ActionChains(driver).release().perform()
            except:
                break
        time.sleep(2)
        driver.quit()
    
    
    
    
    
    
    
    if __name__ == '__main__':
        selum_chrome()
    
    
    
    

    相关文章

      网友评论

          本文标题:USA秒杀

          本文链接:https://www.haomeiwen.com/subject/prupiqtx.html