zoukankan      html  css  js  c++  java
  • 自动获取搬瓦gong最新优惠码脚本

    介绍

    搬瓦gong优惠码信息是隐藏在具体商品购买页面的,所以整个的脚本流程可以分为两步:

    1. 在商品页面正则出这个隐藏的优惠码
    2. 在购买页面测出这个优惠码的优惠力度

    原因是执行https://github.com/flyzy2005/get_bwh_promo_codes脚本失败,原来是https://bwh1.net打不开了,变成了https://bwh88.net 所以更新了以下脚本。

    参考

    https://www.bwgyhw.cn/bandwagonhost-how-to-get-latest-promo-codes/

    https://github.com/flyzy2005/get_bwh_promo_codes

    脚本

    # -*- coding:utf-8 -*-
    
    import csv
    import re
    import time
    import requests
    import sys
    
    BWH_PROMO_CODE_URL = 'https://bwh88.net/cart.php?a=add&pid=44'
    BWH_CHECK_DISCOUNT_URL = 'https://bwh88.net/cart.php?a=view'
    BWH_vps_hosting = 'https://bwh88.net/vps-hosting.php'
    CODES = []
    
    def logo():
        print("""
      _____ _             _        _____      _   
     / ____| |           | |      / ____|    | |  
    | (___ | |_ _   _  __| |_   _| |     __ _| |_ 
     \___ | __| | | |/ _` | | | | |    / _` | __|
     ____) | |_| |_| | (_| | |_| | |___| (_| | |_ 
    |_____/ \__|\__,_|\__,_|\__, |\_____\__,_|\__|
                             __/ |                
                            |___/     
                             
                https://www.cnblogs.com/StudyCat/
                 
        """)
    
    def regex_promo_code():
        try:
            Default_Header = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                              'Referer': BWH_vps_hosting,
                              'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.87 Safari/537.36'
                              }        
            r = requests.get(BWH_PROMO_CODE_URL, headers=Default_Header)
            if r.status_code == 200:
                code_html = r.text
                code = re.search(r'Try this promo code: (w*)', code_html)
                return code[1]
            else:
                return
        except Exception as e:
            print(e)
            return
    
    
    def check_promo_code(code):
        try:
            data = {'promocode': code}
            Default_Header = {'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                              'Referer': BWH_PROMO_CODE_URL,
                              'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.87 Safari/537.36'
                              }           
            r = requests.post(BWH_CHECK_DISCOUNT_URL, headers=Default_Header, data=data)
            if r.status_code == 200:
                check_html = r.text
                discount = re.search(r'- ([d.]+)%', check_html)
                return discount[0]
            else:
                return
        except Exception as e:
            print(e)
            return
    
    def save_to_file(code, discount):
        with open('codes.csv', "a") as file:
            writer = csv.writer(file)
            writer.writerow([code, discount])     
    
    if __name__ == "__main__":
        logo()
        try:
            while True:
                g_code = regex_promo_code()
                if g_code:
                    g_discount = check_promo_code(g_code)
                    if g_discount and g_code not in CODES:
                        CODES.append(g_code)
                        save_to_file(g_code, g_discount)
                        print("Promocode: %s    Discount: %s" % (g_code, g_discount))
                time.sleep(5)
        except KeyboardInterrupt:
            print("Caught KeyboardInterrupt, quitting...")
            sys.exit(1)    
    

      

  • 相关阅读:
    qt的.pro配置总结
    【GOJ 1489】Monster Hunter
    CPU 杂谈
    【CF 1061C|GOJ 3505】Multiplicity
    【CF 1039D|GOJ 3502】You Are Given a Tree
    我跳过的坑
    【CF 1101D|GOJ 3501】GCD Counting
    【HDU 5269|GOJ 739】xor的最低位
    beta阶段组间的140字互评
    【第七周】【新蜂站会】3
  • 原文地址:https://www.cnblogs.com/StudyCat/p/12252062.html
Copyright © 2011-2022 走看看