-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSupremeBot.py
More file actions
158 lines (95 loc) · 4.88 KB
/
SupremeBot.py
File metadata and controls
158 lines (95 loc) · 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
from bs4 import BeautifulSoup
import urllib.request
import re
import requests
import random
import webbrowser
import csv
import threading
import requests
from selenium import webdriver
import time
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from tkinter import *
import winreg
import datetime
global isContinue
global isFirst
isFirst = True
isContinue = 1
while(isContinue == 1):
#set Chrome profile
print('Open Chrome')
if isFirst:
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\Allan\\AppData\\Local\\Google\\Chrome\\User Data")
driver = webdriver.Chrome(executable_path ="D:\\Desktop\\python\\chromedriver.exe",options = options)
isFirst = False
ontime = False
print('First time , enter any button to start')
input()
#Start to scrap Supreme
SupUrl = "http://www.supremenewyork.com"
#0'new'',1'shirts',2'tops_sweaters',3'shorts',4't-shirts',5'hats',6'bags',7'accessories',8'skate
category = ['new','shirts','tops_sweaters','shorts','t-shirts','hats','bags','accessories','skate']
print("Grabbing URL")
r = requests.get('http://www.supremenewyork.com'+'/shop'+'/all'+'/'+category[8])
soup = BeautifulSoup(r.text,'html.parser')
CSOUP = soup.find_all('div',{"class":"inner-article"})
array_length = len(CSOUP)
print(array_length)
#Type what u want
WantedName = 'Truck'
UrlList = []
WantedList = []
DesiredUrl = []
isFound = False
#Get each item's URL
for i in range(array_length):
UrlList.append(CSOUP[i].find('a').get('href'))
ItemRequest = requests.get(SupUrl+UrlList[i])
EachSoup = BeautifulSoup(ItemRequest.text,'html.parser')
ItemList = EachSoup.find_all('h1')
EachName = ItemList[1].get_text()
print(EachName)
if WantedName in EachName:
#print(EachName)
DesiredUrl.append(SupUrl+UrlList[i])
print(DesiredUrl)
break
#print(SupUrl+UrlList[i])
#add to cart
driver.get(DesiredUrl[0])
## driver.find_element_by_xpath('//*[@id="size"]').send_keys('Medium')
driver.find_element_by_xpath('//*[@id="add-remove-buttons"]/input').click()
#wait
locatorCart=(By.XPATH,'//*[@id="cart"]/a[1]')
WebDriverWait(driver, 20, 0.2).until(EC.visibility_of_element_located(locatorCart))
driver.get('https://www.supremenewyork.com/checkout')
#auto fill
##driver.find_element_by_xpath('//*[@id="credit_card_last_name"]').send_keys("Allan")
##driver.find_element_by_xpath('//*[@id="credit_card_first_name"]').send_keys("Wang")
##driver.find_element_by_xpath('//*[@id="order_email"]').send_keys("allanswer3@gmail.com")
##driver.find_element_by_xpath('//*[@id="order_tel"]').send_keys("0955235888")
##driver.find_element_by_xpath('//*[@id="order_billing_state"]').send_keys("東京都")
##driver.find_element_by_xpath('//*[@id="order_billing_city"]').send_keys("Chicago")
##driver.find_element_by_xpath('//*[@id="order_billing_address"]').send_keys("Taipei")
##driver.find_element_by_xpath('//*[@id="order_billing_zip"]').send_keys("114")
##driver.find_element_by_xpath('//*[@id="credit_card_type"]').send_keys("Mastercard")
##driver.find_element_by_xpath('//*[@id="cnb"]').send_keys("1111222233335555")
##driver.find_element_by_xpath('//*[@id="credit_card_month"]').send_keys("12")
##driver.find_element_by_xpath('//*[@id="credit_card_year"]').send_keys("25")
##driver.find_element_by_xpath('//*[@id="vval"]').send_keys("888")
##driver.find_element_by_xpath('//*[@id="order_terms"]').click()
driver.find_element_by_css_selector('.checkout').click()
print('Got you!!')
print('Continue?')
isContinue = int(input())
print(isContinue)
if isContinue == 1:
driver.execute_script("window.open('http://google.com', 'new_window')")
driver.switch_to_window(driver.window_handles[0])