Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from selenium import webdriver
- from selenium.webdriver.common.keys import Keys
- from selenium.webdriver.chrome.options import Options
- from selenium.webdriver.support import expected_conditions as EC
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.common.by import By
- import random
- from random import choice
- from time import sleep, time
- import requests, csv, sys, zipfile, json, email, imaplib, re
- import faker
- fake_names = faker.Faker()
- COUNTRY = "CN" #CN, GB, US
- WINDOW_X, WINDOW_Y = 1100, 800
- def my_proxy(PROXY_HOST,PROXY_PORT, username, password): # PROXY_HOST,PROXY_PORT
- if username:
- manifest_json = """
- {
- "version": "1.0.0",
- "manifest_version": 2,
- "name": "Chrome Proxy",
- "permissions": [
- "proxy",
- "tabs",
- "unlimitedStorage",
- "storage",
- "<all_urls>",
- "webRequest",
- "webRequestBlocking"
- ],
- "background": {
- "scripts": ["background.js"]
- },
- "minimum_chrome_version":"22.0.0"
- }
- """
- background_js = """
- var config = {
- mode: "fixed_servers",
- rules: {
- singleProxy: {
- scheme: "http",
- host: '%s',
- port: parseInt('%s')
- },
- bypassList: ["foobar.com"]
- }
- };
- chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
- function callbackFn(details) {
- return {
- authCredentials: {
- username: '%s',
- password: '%s'
- }
- };
- }
- chrome.webRequest.onAuthRequired.addListener(
- callbackFn,
- {urls: ["<all_urls>"]},
- ['blocking']
- );
- """% (PROXY_HOST, PROXY_PORT, username, password)
- pluginfile = 'proxy_auth_plugin.zip'
- with zipfile.ZipFile(pluginfile, 'w') as zp:
- zp.writestr("manifest.json", manifest_json)
- zp.writestr("background.js", background_js)
- co = Options()
- co.add_argument("--start-maximized")
- co.add_extension(pluginfile)
- else:
- co = webdriver.ChromeOptions()
- co.add_argument('--proxy-server=%s' % PROXY_HOST+":"+PROXY_PORT)
- co.add_argument('--disable-gpu')
- co.add_argument('--log-level=3')
- #co.add_argument('--headless')
- co.add_experimental_option("prefs", {"profile.managed_default_content_settings.images":2})
- driver = webdriver.Chrome("C:/python/chromedriver.exe", chrome_options=co)
- return driver
- _WebDriverWait = WebDriverWait
- def WebDriverWait(driver, time):
- try:
- error_view = driver.find_element_by_xpath("//div[@id='nike-unite-error-view']")
- except:
- return _WebDriverWait(driver, time)
- else:
- if error_view.is_displayed():
- raise NameError("Communication error.")
- else:
- return _WebDriverWait(driver, time)
- def main(USERNAME, PASSWORD, count, total):
- while True:
- check=0
- try:
- base_url = 'https://www.nike.com/%s/launch/' %COUNTRY.lower()
- proxy_list = []
- fname = fake_names.name().split(' ')[0]
- lname = fake_names.name().split(' ')[1]
- if len(proxy_list) > 0:
- proxy = choice(proxy_list) # random choice of proxy
- split = proxy.split(':')
- proxy_host, proxy_port = split[0], split[1]
- if len(split) != 2:
- username, password = split[2], split[3]
- else:
- username, password = False, False
- driver = my_proxy(proxy_host, proxy_port, username, password)
- else:
- co = webdriver.ChromeOptions()
- co.add_argument('--disable-gpu')
- co.add_argument('--log-level=3')
- #co.add_argument('--headless')
- co.add_experimental_option("prefs", {"profile.managed_default_content_settings.images":2})
- driver = webdriver.Chrome("C:/python/chromedriver.exe", chrome_options=co)
- driver.set_window_size(WINDOW_X, WINDOW_Y)
- driver.get(base_url) # browser gets the url
- start = int(time())
- shoe_choice = choice(['https://www.nike.com/cn/launch/t/air-force-1-low-y2k-triple-black/','https://www.nike.com/cn/launch/t/air-huarache-gripp-black-white-team-orange/',
- 'https://www.nike.com/cn/launch/t/air-vapormax-2019-club-gold-ember-glow-light-cream/','https://www.nike.com/cn/launch/t/air-force-1-low-y2k-triple-white/','https://www.nike.com/cn/launch/t/air-max-97-bw-metallic-gold-black-university-red/',
- 'https://www.nike.com/cn/launch/t/womens-air-max-270-white-metallic-summit-white/','https://www.nike.com/cn/launch/t/acg-ruckel-ridge-light-british-tan-habanero-red-black/','https://www.nike.com/cn/launch/t/blazer-low-premium-campfire-orange-white/'])
- size_choice = '//*[contains(concat( " ", @class, " " ), concat( " ", "ta-sm-c", " " )) and (((count(preceding-sibling::*) + 1) = '+choice(['2','3','4','5','6','7','8'])+') and parent::*)]//*[contains(concat( " ", @class, " " ), concat( " ", "size-grid-button", " " ))]'
- addy = choice(['19 mildred street','98 mild street','89 mild street','9 mood','hi street','yuh uh syee','81 mildred','69 okay ni','lol street'])
- postcode = str(random.randint(000000, 999999))
- phone = '1'+ str(random.randint(0000000000, 9999999999))
- try:
- WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, "//*[text()='Yes, I Accept']"))).click()
- except:
- pass
- sleep(5)
- WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//*[@id='root']/div/div/div[1]/div/header/div[1]/section/ul/li[1]/button"))).click()
- sleep(2)
- WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, "//*[text()='使用电子邮件登录。']"))).click()
- WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, '//input[@type="email"]'))).send_keys(user)
- WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, '//input[@type="password"]'))).send_keys(pwd)
- WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, '//div/input[@type="button"]'))).click()
- sleep(5)
- driver.get(shoe_choice)
- sleep(5)
- WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, "//*[text()='尺码 ']"))).click()
- WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, size_choice))).click()
- sleep(5)
- WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, "//*[text()='加入购物车']"))).click()
- sleep(20)
- WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, '//*[contains(concat( " ", @class, " " ), concat( " ", "jewel-cart-container", " " ))]'))).click()
- sleep(10)
- check=1
- WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, '//*[(@id = "ch4_cartCheckoutBtn")]'))).click()
- sleep(10)
- try:
- WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[(@id = "lname")]'))).send_keys(lname)
- WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[(@id = "fname")]'))).send_keys(fname)
- WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[contains(concat( " ", @class, " " ), concat( " ", "js-state", " " ))]'))).click()
- sleep(2)
- WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="province"]/div/div/select/option[15]'))).click()
- WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[contains(concat( " ", @class, " " ), concat( " ", "js-city", " " ))]'))).click()
- WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="city"]/div/div/select/option[8]'))).click()
- WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="district"]/option[3]'))).click()
- WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[contains(concat( " ", @class, " " ), concat( " ", "js-address1", " " ))]'))).send_keys(addy)
- WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[(@id = "postalCodeField")]'))).send_keys(postcode)
- WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[(@id = "phoneNumber")]'))).send_keys(phone)
- sleep(10)
- WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[(@id = "shippingSubmit")]'))).click()
- except:
- pass
- sleep(10)
- try:
- WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[(@id = "individualName")]'))).send_keys(lname)
- except:
- pass
- WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, '//*[contains(concat( " ", @class, " " ), concat( " ", "ch4_btnPlaceOrder", " " ))]'))).click()
- sleep(30)
- driver.quit()
- except Exception as s:
- print (s)
- driver.quit()
- if check==1:
- break
- else:
- driver.quit()
- print('Successfull ' + user)
- if check==1:
- break
- if __name__ == '__main__':
- accounts = [line.rstrip('\n') for line in open('accounts.txt')]
- count = 1
- for user in accounts:
- spt = user.split(":")
- user = spt[0]
- pwd = spt[1]
- try:
- main(user,pwd, count,len(accounts))
- except Exception as e:
- print ("An error occurred: %s" %(e))
- count += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement