-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot.py
More file actions
83 lines (71 loc) · 3.15 KB
/
bot.py
File metadata and controls
83 lines (71 loc) · 3.15 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
import requests
import bs4
from splinter import Browser
from selenium import webdriver
executable_path = {'executable_path': r'C:\Users\Paulito\Desktop\chromedriver_win32\chromedriver'}
class SupremeBot:
def __init__(self, **info):
self.home = 'http://www.supremenewyork.com/'
self.shop_url = 'shop/all/'
self.checkout_url = 'checkout/'
self.info = info
def home_page(self):
self.browser = Browser('chrome', **executable_path)
def find_product(self):
r = requests.get("{}{}{}".format(self.home, self.shop_url, self.info['category'])).text
soup = bs4.BeautifulSoup(r, "lxml")
all_links = []
needed_links = []
for item in soup.find_all('a', href=True):
all_links.append((item['href'], item.text))
for link in all_links:
if link[1] == self.info['product'] or link[1] == self.info['color']:
needed_links.append(link[0])
self.final_link = list(set([x for x in needed_links if needed_links.count(x)==2]))[0]
return self.final_link
def visit_site(self):
self.browser.visit('{}{}'.format(self.home, self.final_link))
self.browser.find_option_by_text(self.info['size']).click()
self.browser.find_by_value('add to cart').click()
def check_out(self):
self.browser.visit('{}{}'.format(self.home, self.checkout_url))
self.browser.find_by_id('order_billing_name').fill(self.info['name'])
self.browser.find_by_id('order_email').fill(self.info['email'])
self.browser.find_by_id('order_tel').fill(self.info['phone'])
self.browser.find_by_id('bo').fill(self.info['addy'])
self.browser.find_by_id('oba3').fill(self.info['apt'])
self.browser.find_by_id('order_billing_zip').fill(self.info['zipfield'])
self.browser.find_by_id('order_billing_city').fill(self.info['city'])
self.browser.find_by_id('order_billing_name').fill(self.info['name'])
self.browser.find_option_by_text(self.info['country']).click()
self.browser.find_by_id('rnsnckrn').fill(self.info['number'])
card_month = self.browser.find_by_id('credit_card_month').first
card_month.select(self.info['month'])
card_year = self.browser.find_by_id('credit_card_year').first
card_year.select(self.info['year'])
self.browser.find_by_id('orcer').fill(self.info['ccv'])
if __name__ == "__main__":
INFO = {
"product": "Raglan Court Jacket",
"color": "Olive",
"size": "Large",
"category": "jackets",
"name": "Blah Blah",
"email": "xxxx@gmail.com",
"phone": "123-456-7890",
"addy": "111 5th St",
"apt": 'XXXX',
"city": "xxxxx",
"zipfield": "90715",
"country": "USA",
"card": 'visa',
"number": "XXXXXXXXXXXXXXXX",
"month": '05',
"year": '2022',
"ccv": "XXXX"
}
bot = SupremeBot(**INFO)
bot.home_page()
bot.find_product()
bot.visit_site()
bot.check_out()