华为商城抢购手机的Python脚本 Python script of Huawei Store snapping up mobile phones

Overview

HUAWEI STORE GO 2021

说明

基于Python3+Selenium的华为商城抢购爬虫脚本,修改自近两年没更新的项目BUY-HW,为女神抢Nova 8(什么时候华为开始学小米玩饥饿营销了?)

原项目的登陆以及抢购部分已经不可用,本项目对原项目进行了改正以适应新华为商城,并增加一些功能。

软件安装及配置可参考原作者文章:Python+Selenium基础入门及实践的第一部分教学Selenium+Python环境搭建及配置。

本项目测试环境:

macOS Big sur 11.2 Beta + Python3.9.1 + Chrome 87.0.4280.141 + Chrome Driver 87.0.4280.88实测正常可用

windows10 + Python3.6 + Chrome 87.0.4280.141 + Chrome Driver 87.0.4280.88实测正常可用

**本python脚本仅供大家学习交流,严禁严禁用于商业用途,不得利用本项目进行任何形式的盈利活动,请在24小时内删除 **

如果本项目对你有所帮助,麻烦项目给个星星鼓励一下哦

如何使用

对于普通玩家,直接下载HUAWEI STORE.py

  • 参考原作者文章:Python+Selenium基础入门及实践的第一部分教学进行Selenium+Python环境搭建及配置(程序猿忽略)。

  • 配置demo.py中的ACCOUNTS信息,第一个为华为账户账号/电话/邮箱,第二个为账户密码。

    • 关于使用多账号(不建议,没有测试),每个信息之间用 , 隔开,形如:

      ACCOUNTS = {
          "账号1": "密码1",
          "账号2": "密码2",
          ................
          "账号n": "密码n"
      }

    Ps:不可使用同一账号

  • 配置chrome_driver属性,为计算机上下载的Chrome Driver路径。对于Windows,一般在Chrome安装目录下(C:\Google\ChromeApplication\chrome.exe)或者Python安装路径下(如原作者文章)。

  • 配置BUY_URL,为你要抢购的商品的华为商城链接。比如华为Nova8 https://www.vmall.com/product/10086232069466.html最好剥离后面乱七八糟的参数,只留下形如 https://www.vmall.com/product/这里是一坨数字.html 的形式

  • 配置BEGIN_GO,开始抢购时间,建议比开售时间提前10-30s,并提前2-5分钟启动python脚本,确保登陆成功,进入页面。

  • 配置AUTO_SELECT,是否自动选择手机参数,比如颜色、版本、套餐,1为开启,0为关闭,否则程序会默认抢网页上的默认颜色、版本、套餐(一般是第一个)。如果你只要默认的颜色版本套餐,请AUTO_SELECT=0,这样可以稍微加快抢的速度并且大大降低一些错误(准备在下一个版本尝试修复)。如果你需要选其他颜色和版本套餐,请AUTO_SELECT=1,并且配置下面的选项:

    • AUTO_COLOR 是否启动自动选手机颜色,并且配置 COLOR 。例如 AUTO_COLOR=1 COLOR='8号色'

    • AUTO_EDITION 是否启动自动选手机颜色,并且配置 EDITION 。例如 AUTO_EDITION=1 EDITION='5G全网通 8GB+256GB'

    • AUTO_COMBO 是否启动自动选手机颜色,并且配置 COLOR 。例如 AUTO_COMBO=1 COMBO='官方标配'

      这些和官网的选项是一致的,请大家务必准确一字不落,包括空格。对于程序员,建议打开控制台选择元素把文字复制出来。

对于开发者,本项目在DEV文件夹中提供了DEV版本,加入了获取配置,免去每次运行脚本webdriver都创建一个新浏览器导致每次都需要验证。只需要第一次验证信任就可以免去验证的麻烦。适用于需要经常测试修改程序的开发者,或者是有一定操作经验的人。此版本无需验证使得从启动到抢购只需要不到十秒。

  • 相对于普通版本,需要额外配置chrome个人资料路径。可以使用自己平常使用的Chrome的所有配置(不推荐,启用其他插件降低脚本效率),可以运行一遍普通版本然后提取所生成的Chrome配置(推荐),也可以直接用我DEV文件夹里提取好的Default配置文件夹(记得改成你的路径哦)。(注意,DEV版如果使用多账号会因为共用一个Chrome个人资料路径导致webdriver无法使用,无解。能力强的可以复制多个个人资料路径,然后写到python里,我暂时懒得搞,毕竟没系统学过python)

  • 对于前两种,如何找到当前这个Chrome的配置路径?直接在地址栏输入chrome://version/就可以看到个人资料路径。

  • 建议到Chrome设置里把首页改为脚本中的LOGIN_URL(https://hwid1.vmall.com/CAS/portal/login.html?validated=一坨一坨reqClientType=26&lang=zh-cn)

    否则使用自己的个人资料路径会出现在登陆界面卡十多秒的情况。目前原因不详。

备注

毕竟是模拟手动,稍微加快了一点速度,剩下的就看网速啦哈哈,当然有较大几率抢购失败哈哈哈哈(脚本的错误我已经改的差不多了,剩下的都是华为和网速的锅),**仅限于学习技术交流,严禁用于商业用途,黄牛走开!!!! **

WHATS NEW

V2.0 2021.1.17

华为的登陆以及抢购等页面有部分修改。重新修改脚本以适应新变化,实测可用。

加入选择配置功能。

优化原脚本部分逻辑,减少错误。

好多好多。。。。。。

V2.1 2021.1.18

修改选择配置部分逻辑,使得后面刷新快的时候也能保证配置选择OK。

上线DEV版本,使得开发者修改测试更加容易。

V2.2 2021.1.19

新增自动获取短信验证码,信任浏览器,加快登陆的操作。

优化大多数可能出错的场景,不限于:

  • 登陆时有时候需要点击两次登陆按钮(不知道华为网页为什么这么干)
  • 偶尔webdriver打开网页错误
  • 优化速度(网速不好的小伙伴自觉把time.sleep( )的数字适当增加)

V3.0 2021.1.20

重写了一半代码,自动获取短信验证码,信任浏览器更加准确,不会出现误判

优化代码格式

优化精简程序的输出

优化逻辑

增加对验证码发送频繁状态的检测以及处理

WHATS NEXT

V2.2版本才注意到这个程序原是可以多账号的,一直只注意主体运行部分,没有注意其他的。准备完善一下多线程多账号。

不过V3.0大概率这是最后一个版本了,要去刷竞赛题了,这个版本基本够用了。。。。。。。。。。。。。。

有脚本+人工抢都抢不到,排队中排个寂寞,买个手机真恶心到了,对华为印象--

ABOUT ME

普通大二狗,没有学习过python,全程都是自己摸索出来的。有问题自己解决吧,百度一下很好使,学过任何一门编程语言的人都能自己摸索着改吧~

Comments
  • 运行的时候出现

    运行的时候出现

    Traceback (most recent call last): File "E:\HUAWEI-STORE-GO-main\HUAWEI STORE.py", line 215, in for account, pwd in data.items(): AttributeError: 'str' object has no attribute 'items'

    question 
    opened by wuan11 10
  • 发生报错

    发生报错

    Exception in thread Thread-1: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 932, in _bootstrap_inner self.run() File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "HUAWEI STORE GO.py", line 324, in loginMall goToBuy(driver, user) File "HUAWEI STORE GO.py", line 178, in goToBuy text = driver.find_elements_by_xpath( IndexError: list index out of range

    bug 
    opened by Broomhildall 3
  • 报错

    报错

    @XYZliang 你好我在用30epro做测试的时候发现报错

    COLOR = '亮黑色'

    EDITION = '5G全网通 256GB'

    COMBO = '官方标配'

    颜色选择错误!请手动选择! 版本选择错误!请手动选择! 套餐选择错误!请手动选择! 2021-02-24 16:46:1215502188239准备完毕,开始等待 Exception in thread Thread-1: Traceback (most recent call last): File "D:\python3.8.8\lib\threading.py", line 932, in _bootstrap_inner self.run() File "D:\python3.8.8\lib\threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "C:/Users/LEgo1/Desktop/HUAWEI-STORE-GO-main (1)/HUAWEI-STORE-GO-main/HUAWEI STORE GO.py", line 324, in loginMall goToBuy(driver, user) File "C:/Users/LEgo1/Desktop/HUAWEI-STORE-GO-main (1)/HUAWEI-STORE-GO-main/HUAWEI STORE GO.py", line 178, in goToBuy text = driver.find_elements_by_xpath( IndexError: list index out of range

    Process finished with exit code 0

    bug 
    opened by Legolii 2
  • 倒计时结束以后没获取到按钮(再运行有了但就要排队了。。)

    倒计时结束以后没获取到按钮(再运行有了但就要排队了。。)

    Traceback (most recent call last): File "C:\Program Files\Python37\lib\threading.py", line 917, in _bootstrap_inner self.run() File "C:\Program Files\Python37\lib\threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "e:\DEV\HUAWEI STORE DEV GO.py", line 351, in loginMall goToBuy(driver, user) File "e:\DEV\HUAWEI STORE DEV GO.py", line 186, in goToBuy if buyButton.get_attribute('class') != 'product-button02 disabled': File "C:\Program Files\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 141, in get_attribute File "C:\Program Files\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 636, in execute_script 'args': converted_args})['value'] File "C:\Program Files\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Program Files\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document (Session info: chrome=88.0.4324.182)

    bug 
    opened by burn1ngsun 1
  • [ImgBot] Optimize images

    [ImgBot] Optimize images

    Beep boop. Your images are optimized!

    Your image file size has been reduced by 34% 🎉

    Details

    | File | Before | After | Percent reduction | |:--|:--|:--|:--| | /DEV/configuration.png | 96.59kb | 62.35kb | 35.45% | | /configuration.png | 96.59kb | 62.35kb | 35.45% | | /PY.png | 406.65kb | 272.79kb | 32.92% | | | | | | | Total : | 599.84kb | 397.50kb | 33.73% |


    Black Lives Matter | 💰 donate | 🎓 learn | ✍🏾 sign

    📝 docs | :octocat: repo | 🙋🏾 issues | 🏅 swag | 🏪 marketplace

    opened by imgbot[bot] 0
  • 排队完到订单确认的界面报错,浏览器自动关闭

    排队完到订单确认的界面报错,浏览器自动关闭

    D:\Python\Python39\python.exe "E:/Downloads/软件/huaweitest/HUAWEI-STORE-GO-main/HUAWEI STORE GO.py" [email protected]成功输入了账号密码,尝试登陆. [email protected]请手动完成认证并登陆! 请输入图形验证码 [email protected]验证码已经发送至136******80 2021-02-26 20:02:[email protected]登录成功!! [email protected]打开购买页面 [email protected]亮黑色选择成功! [email protected]全网通 8GB+128GB选择成功! [email protected]官方标配选择成功! 2021-02-26 20:03:[email protected]准备完毕,开始等待 2021-02-26 20:03:[email protected]未到脚本开启时间,请选择好抢购的颜色、版本、套餐等(若已经配置则忽略),将在设定的脚本启动时间前15秒启动

    2021-02-26 20:04:[email protected]即将开始抢购,程序启动 2021-02-26 20:04:[email protected]可以开始申购,立即申购 [email protected]开始排队:2021-02-26 20:04:50 2021-02-26 20:04:[email protected]:排队中 2021-02-26 20:04:[email protected]:排队中 2021-02-26 20:04:[email protected]:排队中 Exception in thread Thread-1: Traceback (most recent call last): File "D:\Python\Python39\lib\threading.py", line 954, in _bootstrap_inner self.run() File "D:\Python\Python39\lib\threading.py", line 892, in run self._target(*self._args, **self.kwargs) File "E:\Downloads\软件\huaweitest\HUAWEI-STORE-GO-main\HUAWEI STORE GO.py", line 342, in loginMall goToBuy(driver, user) File "E:\Downloads\软件\huaweitest\HUAWEI-STORE-GO-main\HUAWEI STORE GO.py", line 227, in goToBuy onQueue(driver, user) File "E:\Downloads\软件\huaweitest\HUAWEI-STORE-GO-main\HUAWEI STORE GO.py", line 75, in onQueue errorbutton = driver.find_element_by_id("boxCloseBtn") File "D:\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 360, in find_element_by_id return self.find_element(by=By.ID, value=id) File "D:\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element return self.execute(Command.FIND_ELEMENT, { File "D:\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "D:\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="boxCloseBtn"]"} (Session info: chrome=88.0.4324.182)

    Process finished with exit code 0

    win10+python3.9.1+Chrome 88.0.4324.182

    bug 
    opened by highning 11
Owner
ZhangLiang
我喜欢熬夜是因为晚上这段时间完全属于我自己,没有人会在这段时间里要求我去干任何事,我可以毫无心理负担的在这段时间里做任何我想做的事情。 ​​​
ZhangLiang
This is the main repository of open-sourced speech technology by Huawei Noah's Ark Lab.

Speech-Backbones This is the main repository of open-sourced speech technology by Huawei Noah's Ark Lab. Grad-TTS Official implementation of the Grad-

HUAWEI Noah's Ark Lab 295 Jan 7, 2023
PocketSphinx is a lightweight speech recognition engine, specifically tuned for handheld and mobile devices, though it works equally well on the desktop

PocketSphinx 5prealpha This is PocketSphinx, one of Carnegie Mellon University's open source large vocabulary, speaker-independent continuous speech r

null 3.2k Dec 28, 2022
official ( API ) for the zAmericanEnglish app in [ Google play ] and [ App store ]

official ( API ) for the zAmericanEnglish app in [ Google play ] and [ App store ]

Plugin 3 Jan 12, 2022
Ελληνικά νέα (Python script) / Greek News Feed (Python script)

Ελληνικά νέα (Python script) / Greek News Feed (Python script) Ελληνικά English Το 2017 είχα υλοποιήσει ένα Python script για να εμφανίζει τα τωρινά ν

Loren Kociko 1 Jun 14, 2022
Sentello is python script that simulates the anti-evasion and anti-analysis techniques used by malware.

sentello Sentello is a python script that simulates the anti-evasion and anti-analysis techniques used by malware. For techniques that are difficult t

Malwation 62 Oct 2, 2022
Python generation script for BitBirds

BitBirds generation script Intro This is published under MIT license, which means you can do whatever you want with it - entirely at your own risk. Pl

null 286 Dec 6, 2022
A python script to prefab your scripts/text files, and re create them with ease and not have to open your browser to copy code or write code yourself

Scriptfab - What is it? A python script to prefab your scripts/text files, and re create them with ease and not have to open your browser to copy code

DevNugget 3 Jul 28, 2021
A Python script that compares files in directories

compare-files A Python script that compares files in different directories, this is similar to the command filecmp.cmp(f1, f2). I made this script in

Colvin 1 Oct 15, 2021
A Python script which randomly chooses and prints a file from a directory.

___ ____ ____ _ __ ___ / _ \ | _ \ | _ \ ___ _ __ | '__| / _ \ | |_| || | | || | | | / _ \| '__| | | | __/ | _ || |_| || |_| || __

yesmaybenookay 0 Aug 6, 2021
Simple Python script to scrape youtube channles of "Parity Technologies and Web3 Foundation" and translate them to well-known braille language or any language

Simple Python script to scrape youtube channles of "Parity Technologies and Web3 Foundation" and translate them to well-known braille language or any

Little Endian 1 Apr 28, 2022
A python script that will use hydra to get user and password to login to ssh, ftp, and telnet

Hydra-Auto-Hack A python script that will use hydra to get user and password to login to ssh, ftp, and telnet Project Description This python script w

null 2 Jan 16, 2022
Wrapper to display a script output or a text file content on the desktop in sway or other wlroots-based compositors

nwg-wrapper This program is a part of the nwg-shell project. This program is a GTK3-based wrapper to display a script output, or a text file content o

Piotr Miller 94 Dec 27, 2022
This script just scrapes the most recent Nepali news from Kathmandu Post and notifies the user about current events at regular intervals.It sends out the most recent news at random!

Nepali-news-notifier This script just scrapes the most recent Nepali news from Kathmandu Post and notifies the user about current events at regular in

Sachit Yadav 1 Feb 11, 2022
Script to generate VAD dataset used in Asteroid recipe

About the dataset LibriVAD is an open source dataset for voice activity detection in noisy environments. It is derived from LibriSpeech signals (clean

null 11 Sep 15, 2022
Script to download some free japanese lessons in portuguse from NHK

Nihongo_nhk This is a script to download some free japanese lessons in portuguese from NHK. It can be executed by installing the packages with: pip in

Matheus Alves 2 Jan 6, 2022
A script that automatically creates a branch name using google translation api and jira api

About google translation api와 jira api을 사용하여 자동으로 브랜치 이름을 만들어주는 스크립트 Setup 환경변수에 다음 3가지를 등록해야 한다. JIRA_USER : JIRA email (ex: [email protected]) JIR

hyunwook.kim 2 Dec 20, 2021
Python module (C extension and plain python) implementing Aho-Corasick algorithm

pyahocorasick pyahocorasick is a fast and memory efficient library for exact or approximate multi-pattern string search meaning that you can find mult

Wojciech Muła 763 Dec 27, 2022
Python module (C extension and plain python) implementing Aho-Corasick algorithm

pyahocorasick pyahocorasick is a fast and memory efficient library for exact or approximate multi-pattern string search meaning that you can find mult

Wojciech Muła 579 Feb 17, 2021