├── .github └── stale.yml ├── .gitignore ├── .idea ├── .gitignore ├── auto-buy.iml ├── inspectionProfiles │ └── profiles_settings.xml ├── misc.xml ├── modules.xml └── vcs.xml ├── LICENSE ├── README.md ├── auto_buy.py └── drivers ├── chromedriver_linux64 ├── chromedriver_mac64 └── chromedriver_win32.exe /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 60 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 7 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - pinned 8 | - security 9 | # Label to use when marking an issue as stale 10 | staleLabel: wontfix 11 | # Comment to post when marking an issue as stale. Set to `false` to disable 12 | markComment: > 13 | This issue has been automatically marked as stale because it has not had 14 | recent activity. It will be closed if no further activity occurs. Thank you 15 | for your contributions. 16 | # Comment to post when closing a stale issue. Set to `false` to disable 17 | closeComment: false -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Default ignored files 3 | /workspace.xml -------------------------------------------------------------------------------- /.idea/auto-buy.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 11 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Charley 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 自动购买姬 2 | 3 | [![HitCount](http://hits.dwyl.com/codyi96/auto-buy.svg)](http://hits.dwyl.com/codyi96/auto-buy) 4 | 5 | 淘宝/天猫抢购小助手,Python练手项目。 6 | 7 | ## 功能 8 | - 定时抢购 9 | 10 | ## 使用 11 | 1. 安装Python3、Pip3 12 | 2. 运行pip install selenium 13 | 3. 运行python3 auto_buy.py 14 | 4. 根据脚本提示输入对应信息 15 | 16 | ## 参考环境 17 | - Python 3.7 18 | - Chrome 77.0.3865.90 19 | - Win/Mac/Linux 20 | 21 | __仅供学习交流,严禁用于商业用途__ 22 | -------------------------------------------------------------------------------- /auto_buy.py: -------------------------------------------------------------------------------- 1 | import os 2 | import platform 3 | import time 4 | import datetime 5 | from selenium import webdriver 6 | 7 | 8 | def get_driver(): 9 | os_type = platform.system() 10 | root_dir = os.path.dirname(os.path.abspath(__file__)) 11 | drivers_dir = os.path.join(root_dir, 'drivers') 12 | if os_type == 'Darwin': 13 | return os.path.join(drivers_dir, 'chromedriver_mac64') 14 | elif os_type == 'Windows': 15 | return os.path.join(drivers_dir, 'chromedriver_win32.exe') 16 | elif os_type == 'Linux': 17 | return os.path.join(drivers_dir, 'chromedriver_linux64') 18 | else: 19 | return None 20 | 21 | 22 | def open_website(chrome, url): 23 | chrome.get(url) 24 | chrome.implicitly_wait(10) 25 | 26 | 27 | def buy(chrome, store, buy_time): 28 | # 淘宝 29 | if store == '1': 30 | # "立即购买"的css_selector 31 | btn_buy = '#J_juValid > div.tb-btn-buy > a' 32 | # "立即下单"的css_selector 33 | btn_order = '#submitOrderPC_1 > div.wrapper > a' 34 | # 天猫 35 | elif store == '2': 36 | btn_buy = '#J_LinkBuy' 37 | btn_order = '#submitOrderPC_1 > div > a' 38 | # 天猫超市 39 | elif store == '3': 40 | btn_buy = '#J_Go' 41 | btn_order = '#submitOrderPC_1 > div > a.go-btn' 42 | 43 | while True: 44 | # 现在时间大于预设时间则开售抢购 45 | if datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') > buy_time: 46 | try: 47 | # 找到"立即购买" 点击 48 | if chrome.find_element_by_css_selector(btn_buy): 49 | chrome.find_element_by_css_selector(btn_buy).click() 50 | break 51 | time.sleep(0.1) 52 | except: 53 | time.sleep(0.3) 54 | 55 | while True: 56 | try: 57 | # 找到"立即下单" 点击 58 | if chrome.find_element_by_css_selector(btn_order): 59 | chrome.find_element_by_css_selector(btn_order).click() 60 | # 下单成功,跳转至支付页面 61 | print('购买成功') 62 | break 63 | except: 64 | time.sleep(0.5) 65 | 66 | 67 | if __name__ == "__main__": 68 | driver_location = get_driver() 69 | if driver_location is None: 70 | print('不支持的系统类型!') 71 | exit(-1) 72 | chrome = webdriver.Chrome(driver_location) 73 | # chrome.maximize_window() 74 | url = input('请输入链接\n - 淘宝/天猫:输入商品链接;\n - 天猫超市:输入购物车链接并勾选预购商品;\n') 75 | store = input('请输入商城序号:\n1. 淘宝\n2. 天猫\n3. 天猫超市\n') 76 | buy_time = input('请输入抢购时间:\neg. 2019-10-15 00:00:00\n') 77 | print('请手动登录(务必在抢购时间前完成)') 78 | open_website(chrome, url) 79 | buy(chrome, store, buy_time) 80 | -------------------------------------------------------------------------------- /drivers/chromedriver_linux64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codyi96/auto-buy/630211aabcf7f50fe99895ab088c0a9647e057c5/drivers/chromedriver_linux64 -------------------------------------------------------------------------------- /drivers/chromedriver_mac64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codyi96/auto-buy/630211aabcf7f50fe99895ab088c0a9647e057c5/drivers/chromedriver_mac64 -------------------------------------------------------------------------------- /drivers/chromedriver_win32.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codyi96/auto-buy/630211aabcf7f50fe99895ab088c0a9647e057c5/drivers/chromedriver_win32.exe --------------------------------------------------------------------------------