forked from applerich/ShopifyCheckout
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshopify.py
More file actions
173 lines (143 loc) · 6.59 KB
/
shopify.py
File metadata and controls
173 lines (143 loc) · 6.59 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#-*- coding: utf-8 -*-
import requests, time, json, sys, datetime
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import Select
from config import *
session = requests.session()
chromedriver = "/Users/alexb_000/Documents/CODING/gui/bin/chromedriver"
driver = webdriver.Chrome(chromedriver)
#urlOfCrappyItem = raw_input("Enter Yeezy Link: ")
#urlOfYeezy = raw_input("Enter Yeezy Link: ")
urlOfYeezy = "https://yeezysupply.com/products/mens-combat-boot-light-sand/"
cartLink = "https://yeezysupply.com/cart/"
shopifyServerCheckoutLink = "https://purchase.yeezysupply.com"
size = "42"
def writeToFile(message):
with open('logFile.txt','a') as logFile:
logFile.write(message)
def scrapeForVariant():
##############################################################################
#VARIANT SCRAPING ADDING TO CART AND GETTING TO CUSTOMER INFO PAGE, ALSO SET UP FOR QUEUE BYPASS
##############################################################################
writeToFile('\nNEW SHOPIFY SESSION\n' + str(datetime.datetime.now()) + "\n\n")
try:
driver.get(urlOfYeezy)
soup = BeautifulSoup(driver.page_source, 'html.parser')
selectSizesTag = soup.findAll('option')
for item in selectSizesTag:
if size in item:
global variantOfYeezy
variantOfYeezy = item['value']
except Exception as e:
writeToFile(e)
frontEndCheckout()
writeToFile('Got the variant of desired shoe.\n')
def submitCustomerInfo():
##############################################################################
#GENERATING CHECKOUT LINK, SUBMITTING CUSTOMER INFO, GETTING COOKIES AND GETTING TO PAYMENT PAGE
##############################################################################
submitCustomerInfoHeaders = {
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Encoding':'gzip, deflate, br',
'Accept-Language':'en-US,en;q=0.8',
'Connection':'keep-alive',
'Content-Type':'application/x-www-form-urlencoded',
'Origin':shopifyServerCheckoutLink,
'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
}
try:
resp = session.get(cartLink+variantOfYeezy+":1", allow_redirects=True, headers=submitCustomerInfoHeaders, timeout=4)
except Exception as e:
writeToFile(e)
frontEndCheckout()
if b'Continue to shipping method' in resp.content:
writeToFile('Got to Customer Information Page.\n')
global shopifyGeneratedCheckoutLink
shopifyGeneratedCheckoutLink = resp.url
soup = BeautifulSoup(resp.content, 'html.parser')
authenticity_token = soup.findAll('input', {'name':'authenticity_token'})[2]['value']
customerInfoData = {
#params to pass
'utf8' : '✓',
'_method' : 'patch',
'authenticity_token' : authenticity_token,
'previous_step' : 'contact_information',
'step':'shipping_method',
'checkout[email]' : email,
'checkout[buyer_accepts_marketing]' : '0',
'checkout[buyer_accepts_marketing]' : '1',
'checkout[shipping_address][first_name]' : firstName,
'checkout[shipping_address][last_name]': lastName,
'checkout[shipping_address][address1]' : address1,
'checkout[shipping_address][address2]' : address2,
'checkout[shipping_address][city]' : city,
'checkout[shipping_address][country]' : country,#United States
'checkout[shipping_address][province]' : province, #Ohio
'checkout[shipping_address][zip]' : zipCode,
'checkout[shipping_address][phone]' : phone, #no spaces
'checkout[shipping_address][first_name]' : firstName,
'checkout[shipping_address][last_name]' : lastName,
'checkout[shipping_address][address1]' : address1,
'checkout[shipping_address][address2]' : address2,
'checkout[shipping_address][city]' : city,
'checkout[shipping_address][country]' : country,
'checkout[shipping_address][province]' : province,
'checkout[shipping_address][zip]' : zipCode,
'checkout[shipping_address][phone]' : phone,
'g-recaptcha-response' : '',
'button' : '',
'checkout[client_details][browser_width]' : '527',
'checkout[client_details][browser_height]' : '620',
'checkout[client_details][javascript_enabled]' : '1'
}
try:
resp = session.post(shopifyGeneratedCheckoutLink, data=customerInfoData, allow_redirects=True,timeout=4)
except Exception as e:
writeToFile(e)
frontEndCheckout()
if(resp.status_code == 200):
writeToFile('Successfully submitted customer info to shopify server.\n')
else:
driver.quit()
resp = session.get(shopifyGeneratedCheckoutLink+"?previous_step=shipping_method&step=payment_method", allow_redirects=True, timeout=4)
if b'Complete order' or b'Complete order'.upper in resp.content:
writeToFile('Successfully bypassed captcha and got to payment method page.\n')
soup = BeautifulSoup(resp.content, 'html.parser')
global newAuthToken
newAuthToken = soup.findAll('input', {'name':'authenticity_token'})[2]['value']
def submitPayment():
##############################################################################
#SUBMITTING PAYMENT METHOD, GETTING UNIQUE SESSION ID
##############################################################################
submitPaymentSessionHeaders = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36',
'Content-Type': 'application/json'
}
ccINfo = {
"credit_card": {
"number": cardNumber,
"name": cardFirstNameAndLastName,
"month": cardMonth,
"year": cardYear,
"verification_value": CVV
}
}
try:
r = session.post('https://elb.deposit.shopifycs.com/sessions', data=json.dumps(ccINfo), headers = submitPaymentSessionHeaders, timeout=4, allow_redirects=True)
except Exception as e:
writeToFile(e)
frontEndCheckout()
if r.status_code == 200:
writeToFile('Retrieved unique session ID.\n')
else:
writeToFile(str(r.status_code)+"\n")
sessionIDvalue = json.loads(str(r.text))
driver.quit()
def frontEndCheckout():
print('No function yet')
if __name__ == "__main__":
scrapeForVariant()
submitCustomerInfo()
submitPayment()