SHOW:
|
|
- or go back to the newest paste.
1 | import bs4, time | |
2 | from selenium import webdriver | |
3 | from selenium.webdriver.common.by import By | |
4 | from selenium.webdriver.support.ui import WebDriverWait | |
5 | from selenium.webdriver.support import expected_conditions as EC | |
6 | ||
7 | #current bugs | |
8 | #sometimes fails to add shoe to cart, when this happens restart the script | |
9 | ||
10 | #put url of shoes | |
11 | url = 'http://www.footlocker.com/product/model:254106/sku:AQ2661/adidas-originals-yeezy-boost-350-mens/?cm=' | |
12 | ||
13 | #personal information | |
14 | fname = 'Alex' | |
15 | lname = 'Fend' | |
16 | street2 = '462 E. Grove St.' | |
17 | zipcode2 = '91767' | |
18 | city2 = 'Pomona' | |
19 | phone2 = '9095308362' | |
20 | email2 = 'thisisjohns2mail3@gmail.com' | |
21 | creditcardnumber = '4266841424986345' | |
22 | creditcardmonth = '10' | |
23 | creditcardyear = '18' | |
24 | credticardcsv = '222' | |
25 | ||
26 | ||
27 | ###Do not change anything below this line | |
28 | #shoe sizes | |
29 | size6 = '//*[@id="product_sizes"]/option[1]' | |
30 | size65 = '//*[@id="product_sizes"]/option[2]' | |
31 | size7 = '//*[@id="product_sizes"]/option[3]' | |
32 | size75 = '//*[@id="product_sizes"]/option[4]' | |
33 | size8 = '//*[@id="product_sizes"]/option[5]' | |
34 | size85 = '//*[@id="product_sizes"]/option[6]' | |
35 | size9 = '//*[@id="product_sizes"]/option[7]' | |
36 | size95 = '//*[@id="product_sizes"]/option[8]' | |
37 | size10 = '//*[@id="product_sizes"]/option[9]' | |
38 | size105 = '//*[@id="product_sizes"]/option[10]' | |
39 | size11 = '//*[@id="product_sizes"]/option[11]' | |
40 | size115 = '//*[@id="product_sizes"]/option[12]' | |
41 | size12 = '//*[@id="product_sizes"]/option[13]' | |
42 | size125 = '//*[@id="product_sizes"]/option[14]' | |
43 | ||
44 | chosen_size = size10 | |
45 | ||
46 | cart_url = 'http://www.footlocker.com/shoppingcart/default.cfm?sku=' | |
47 | shipping_info_loaded = False | |
48 | credit_info_loaded = False | |
49 | shoe_status = False | |
50 | successful_load = False | |
51 | ||
52 | browser = webdriver.Firefox() | |
53 | ||
54 | while shoe_status == False: | |
55 | browser.get(url) | |
56 | timer_displayed = browser.find_element_by_xpath('//*[@id="select_size"]') | |
57 | print(timer_displayed.is_displayed()) | |
58 | if timer_displayed.is_displayed() == False: | |
59 | shoe_status = True | |
60 | time.sleep(1) #will refresh every x seconds until timer is gone | |
61 | ||
62 | print('Loading page...') | |
63 | while successful_load == False: | |
64 | browser.get(url) | |
65 | print('Successful!') | |
66 | #size | |
67 | print('Selecting size...') | |
68 | (browser.find_element_by_xpath(chosen_size)).click() | |
69 | print('Successful!') | |
70 | #add to cart | |
71 | print('Adding to cart...') | |
72 | add_to_cart = browser.find_element_by_xpath('//*[@id="product_form"]/div/span[2]/div/div[7]/input') | |
73 | add_to_cart.click() | |
74 | print('Successful!') | |
75 | print('Going to cart...') | |
76 | browser.get(cart_url) | |
77 | if browser.current_url != 'http://www.footlocker.com/catalog/emptyCart.cfm?cartIsEmpty=1': | |
78 | print('Going to checkout...') | |
79 | checkout = browser.find_element_by_xpath('//*[@id="cart_checkout_button"]') | |
80 | checkout.click() | |
81 | print('Successful!') | |
82 | print('Going to billing...') | |
83 | successful_load = True | |
84 | checkout.click() | |
85 | ||
86 | #waits for page to load | |
87 | ||
88 | try: | |
89 | element = WebDriverWait(browser, 300).until(EC.presence_of_element_located((By.XPATH, '//*[@id="billFirstName"]'))) | |
90 | print('Page loaded') | |
91 | shipping_info_loaded = True | |
92 | except TimeoutException: | |
93 | print('Page took too long to load') | |
94 | ||
95 | if shipping_info_loaded == True: | |
96 | time.sleep(1) | |
97 | print('Filling out shipping info') | |
98 | first_name = browser.find_element_by_xpath('//*[@id="billFirstName"]') | |
99 | first_name.send_keys(fname) | |
100 | last_name = browser.find_element_by_xpath('//*[@id="billLastName"]') | |
101 | last_name.send_keys(lname) | |
102 | street = browser.find_element_by_xpath('//*[@id="billAddress1"]') | |
103 | street.send_keys(street2) | |
104 | zipcode = browser.find_element_by_xpath('//*[@id="billPostalCode"]') | |
105 | zipcode.send_keys(zipcode2) | |
106 | city = browser.find_element_by_xpath('//*[@id="billCity"]') | |
107 | city.send_keys(city2) | |
108 | city = browser.find_element_by_xpath('//*[@id="billState"]/option[10]') | |
109 | city.click() | |
110 | phone = browser.find_element_by_xpath('//*[@id="billHomePhone"]') | |
111 | phone.send_keys(phone2) | |
112 | email = browser.find_element_by_xpath('//*[@id="billEmailAddress"]') | |
113 | email.send_keys(email2) | |
114 | email.submit() | |
115 | print('Successful!') | |
116 | print('Skipping delivery options') | |
117 | next_step = browser.find_element_by_xpath('//*[@id="billPaneContinue"]') | |
118 | next_step.click() | |
119 | if browser.current_url == 'http://www.footlocker.com/shoppingcart/?sessionExpired=true': | |
120 | successful_load = False | |
121 | print('Button clicked') | |
122 | ||
123 | try: | |
124 | element = WebDriverWait(browser, 300).until(EC.presence_of_element_located((By.XPATH, '//*[@id="shipMethod3"]'))) | |
125 | print('Page passed') | |
126 | next_step_loaded = True | |
127 | print('Successful!') | |
128 | print('Loading next step') | |
129 | if next_step_loaded == True: | |
130 | next_step_2 = browser.find_element_by_xpath('//*[@id="shipMethodPaneContinue"]') | |
131 | next_step_2.click() | |
132 | except TimeoutException: | |
133 | print('Page took too long to load') | |
134 | ||
135 | try: | |
136 | element = WebDriverWait(browser, 300).until(EC.presence_of_element_located((By.XPATH, '//*[@id="payMethodPanestoredCCCardNumber"]'))) | |
137 | print('Page loaded') | |
138 | credit_info_loaded = True | |
139 | except TimeoutException: | |
140 | print('Page took too long to load') | |
141 | ||
142 | if credit_info_loaded == True: | |
143 | time.sleep(1) | |
144 | print('Filling out credit card information') | |
145 | credit_card_number = browser.find_element_by_xpath('//*[@id="CardNumber"]') | |
146 | credit_card_number.send_keys(creditcardnumber) | |
147 | credit_card_number_month = browser.find_element_by_xpath('//*[@id="CardExpireDateMM"]') | |
148 | credit_card_number_month.send_keys(creditcardmonth) | |
149 | credit_card_number_year = browser.find_element_by_xpath('//*[@id="CardExpireDateYY"]') | |
150 | credit_card_number_year.send_keys(creditcardyear) | |
151 | time.sleep(1) | |
152 | print('Filling out csv') | |
153 | credit_card_number_csv = browser.find_element_by_xpath('//*[@id="CardCCV"]') | |
154 | credit_card_number_csv.send_keys(credticardcsv) | |
155 | credit_card_number_csv.submit() | |
156 | print('Successful') |