I am trying to create a python script that login to Nike's website. I checked to make sure all of my submitted data is correct, and it is however, I keep getting a 403 error. I have searched for this issue online and I keep seeing something about '_abck' cookies. I am getting the correct cookies and even tried to get selenium to click around the page before getting the cookies. Can someone point me in the right direction?
options = Options()
#options.headless = True
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(path, options=options)
NIKE_LINK = "https://www.nike.com/launch"
#VISITOR_LINK = "https://unite.nike.com/session.html"
driver.get(NIKE_LINK)
driver.find_element_by_css_selector('#root > div > div > div.main-layout > div > div.ncss-col-sm-12.full > div.feed-header-container > header > div > div > div.filters-menu.mb5-sm.mb0-lg > div > nav > ul > li:nth-child(3) > a').click()
time.sleep(4)
driver.find_element_by_css_selector('#root > div > div > div.main-layout > div > header > div.d-sm-h.d-lg-b > section > div > ul > li.member-nav-item.d-sm-ib.va-sm-m > button').click()
driver.find_element_by_xpath("//input[@name='emailAddress']").send_keys('Deron')
cookies_home = driver.get_cookies()
#driver.get(VISITOR_LINK)
#cookies_visitor = driver.get_cookies()
bi = ''
ab = ''
bm = ''
ak = ''
bz = ''
anon = ''
visitor = ''
#get the visitor token
for cookie in cookies_home:
if cookie['name'] == 'visitData':
get = cookie['value'].split(':')[-1][1:-2]
if not get:
print(clock(), 'Visitor ID was not found')
visitor = get
if cookie['name'] == 'bm_mi':
bm_mi = cookie['value']
bi += bm_mi
if cookie['name'] == '_abck':
abck = cookie['value']
ab += abck
if cookie['name'] == 'bm_sv':
bm_sv = cookie['value']
bm += bm_sv
if cookie['name'] == 'ak_bmsc':
ak_bm = cookie['value']
ak += ak_bm
if cookie['name'] == 'bm_sz':
bm_sz = cookie['value']
bz += bm_sz
if cookie['name'] == 'anonymousId':
anon_id = cookie['value']
anon += anon_id
print(visitor)
headers = {
'sec-ch-ua': '"Google Chrome";v="87", " Not;A Brand";v="99", "Chromium";v="87"',
'sec-ch-ua-mobile': '?0',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36'
}
main_page = s.get('https://www.nike.com/launch', headers=headers)
#r = s.get('https://www.nike.com/')
#visitor = r.headers['X-Request-Id']
soup = BeautifulSoup(main_page.text, 'html.parser')
script = soup.find_all('script')[-13]
script = str(script)
table = script[90:-82]
#converts to JSON
table = json.loads(table)
client = ''
for i in table['staticConfig'].values():
for key, value in i.items():
#Returns two dictionaries
if 'unite' in key:
if 'clientId' in value.keys():
#Strips clutter
max = str(value).split(':')[1].split(',')[0][2:-1]
#Adds to client variable
client += max
print(clock(), 'Client ID found')
head = {
'orgin': 'https://www.nike.com',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36',
'Referer': 'https://www.nike.com/',
'sec-ch-ua':'"Google Chrome";v="87", " Not;A Brand";v="99", "Chromium";v="87"',
'content-type':'application/json',
'content-length': '174'
}
cookies = {
'bm_mi':bi,
'_abck':ab,
'bm_sv':bm,
'ak_bmsc':ak,
'bm_sz':bz,
'anonymousId':anon
}
cook = {
'_abck':ab,
'bm_sz':bz,
}
data = {
'client_id':client,
'grant_type':'password',
'password':password,
'username':email,
'ux_id':'com.nike.commerce.snkrs.web',
}
for cookie in cookies_home:
s.cookies.set(cookie['name'], cookie['value'], path=cookie['path'], domain=cookie['domain'])
params = {
'appVersion': '859',
'experienceVersion': '859',
'uxid': 'com.nike.commerce.snkrs.web',
'locale': 'en_US',
'backendEnvironment': 'identity',
'browser': 'Google%20Inc.',
'os': 'undefined',
'mobile': 'false',
'native': 'false',
'visit': '1',
'visitor': visitor,
}
#'https://unite.nike.com/login?appVersion=859&experienceVersion=859&uxid=com.nike.commerce.snkrs.web'
#'&locale=en_US&backendEnvironment=identity&browser=Google%20Inc.&os=undefined&mobile=false&native=false&visit=1&'
#'visitor=
login_page = s.post('https://unite.nike.com/login?', headers=head, json=data, params=params)
print(login_page.text)
question from:
https://stackoverflow.com/questions/65835837/using-python-requests-to-login-with-nikes-site