Skip to content

Instantly share code, notes, and snippets.

@Natata
Created May 2, 2020 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Natata/871c7ff8100a4defac347c59bc8649ab to your computer and use it in GitHub Desktop.
Save Natata/871c7ff8100a4defac347c59bc8649ab to your computer and use it in GitHub Desktop.
the base
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib
import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import os
import sys
import json
# constants
members = ['https://tebasen.theshop.jp/items/28576772', 'https://tebasen.theshop.jp/items/28576784', 'https://tebasen.theshop.jp/items/28576803', 'https://tebasen.theshop.jp/items/28576811', 'https://tebasen.theshop.jp/items/28576826']
#members = ['https://natata.kawaiishop.jp/items/28581313', 'https://natata.kawaiishop.jp/items/28581322', 'https://natata.kawaiishop.jp/items/28581323', 'https://natata.kawaiishop.jp/items/28581325', 'https://natata.kawaiishop.jp/items/28581326']
url_cart = 'https://c.thebase.in/order/cart/tebasen-theshop-jp'
#url_cart = 'https://c.thebase.in/order/cart/natata-kawaiishop-jp'
default_sleep_time = 0.5
def login():
options = webdriver.ChromeOptions()
driver = webdriver.Chrome('chromedriver', options=options)
print("login...")
return driver
def open_all(driver, urls):
first = True
for member in urls:
if first:
driver.get(member)
first = False
else:
driver.execute_script("window.open('{}');".format(member))
#time.sleep(1)
def buy_all(driver):
boughts = {}
while True:
for h in driver.window_handles:
if h in boughts:
continue
driver.switch_to.window(h)
if canbuy(driver):
boughts[h] = True
time.sleep(0.3)
if len(boughts) == 5:
break
def canbuy(driver):
#btn = driver.find_element_by_css_selector('#purchase_form > div > button')
#print(btn.text)
try:
btn = driver.find_element_by_css_selector('#purchase_form > div > button')
if btn.text == '販売開始までお待ち下さい':
driver.refresh()
return False
else:
btn.click()
return True
except Exception as e:
print(e)
print(driver.current_url)
driver.refresh()
def say(text):
try:
layout = 'say {}'
os.system(layout.format(text))
except:
print('cannot say {}'.format(text))
def buy_single(url):
driver = login()
driver.get(url)
while True:
if canbuy(driver):
break
btn = driver.find_element_by_partial_link_text('ゲストとして購入')
btn.click()
if __name__ == "__main__":
driver = login()
url = "https://tebasen.theshop.jp/items/28769350"
driver.get(url)
while True:
if canbuy(driver):
break
time.sleep(0.3)
#buy_all(driver)
#driver.get(url_cart)
btn = driver.find_element_by_partial_link_text('ゲストとして購入')
btn.click()
#time.sleep(2)
#driver.close()
#driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment