简体   繁体   中英

Cant login into Nike with python selenium

I know there is already one other pretty similar question, but my is a bit different. The problem is, that you cant login into Nike by using Selenium. It worked along time for me, but somehow it stopped working. I was reading a bit about how to bypass that and came to the solution, to just use an older chrome version(I'm using chrome driver). That worked, how ever now its not again and Nike is again blocking the login. The old Version I was using, was 79. The new Version that did worked for me a long time ago and that is the newest Version right now is 90. This is my Code, that tried to login into Nike:

import time 
from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-blink-features")
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
chrome_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")
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options = chrome_options)
driver.get("https://www.nike.com/login")
time.sleep(2)
email = driver.find_element_by_xpath('//input[@type="email"]')
email.send_keys("THE-EMAIL")
password = driver.find_element_by_xpath('//input[@type="password"]')
password.send_keys("THE-PASSWORD")
button = driver.find_element_by_xpath("/html/body/div[2]/div[3]/div[7]/form/div[6]/input")
button.click()

Does someone knows why its blocking selenium? I mean manually I can Login, so its not because of the Account.

The solution given by colossatr0n in this thread Can a website detect when you are using Selenium with chromedriver? worked for me. Here is a partial copy, the idea is to replace cdc_ with another string in order not to be detected:

vim /path/to/chromedriver

After running the line above, you'll probably see a bunch of gibberish. Do the following:

Replace all instances of cdc_ with dog_ by typing:%s/cdc_/dog_/g. dog_ is just an example. You can choose anything as long as it has the same amount of characters as the search string (eg, cdc_), otherwise the chromedriver will fail. To save the changes and quit, type:wq. and press return, If you need to quit without saving changes: type.q! and press return.

I also had to update the line to get the button:

 button = driver.find_element_by_xpath("/html/body/div[4]/div[1]/div[1]/div[1]/div[7]/form/div[6]/input")    

Selenium managed to login!

Currently, Nike uses Akamai along with Kasada as a WAF to catch the bots. You can try to modify your web driver, but it generally doesn't work since Akamai also analyzes your client's behavior on the website.

You have two options:

  • A. Either try to get ignored by Akamai .
  • B. Try to generate valid cookies** by reverse-engineering the Akamai script.

Trying to generate valid cookies is more scalable , since the other methods generally require a lot of Selenium or any other browser-based automation tool usage.

But it’s a lot easier to use browser-based tools rather than reverse-engineering the script . You can try to use undetected-chromedriver with Selenium, it implements many features to conceal your client while connecting to the website. Here's a minimal working example:

# web driver manager: https://github.com/SergeyPirogov/webdriver_manager
# will help us automatically download the web driver binaries
# then we can use `Service` to manage the web driver's state.
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service

from selenium import webdriver
import undetected_chromedriver as uc

options = webdriver.ChromeOptions()
# this returns the path web driver downloaded
chrome_path = ChromeDriverManager().install() 
chrome_service = Service(chrome_path)

driver = uc.Chrome(options=options, use_subprocess=True, service=chrome_service)

url = "https://bot.sannysoft.com/"

driver.get(url)

ss = driver.get_screenshot_as_png()
with open("bot-check.png", "wb") as f:
    f.write(ss)

driver.quit()

Generally, using these tools with a different User-Agent and preferably with proxies is more convenient. Of course, the more you imitate a real user, the better.

You can learn more here: Akamai script .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM