Advertisement
Guest User

Untitled

a guest
Dec 30th, 2018
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.13 KB | None | 0 0
  1. from selenium import webdriver
  2. from selenium.webdriver.common.keys import Keys
  3. from selenium.webdriver.chrome.options import Options
  4. from selenium.webdriver.support import expected_conditions as EC
  5. from selenium.webdriver.support.ui import WebDriverWait
  6. from selenium.webdriver.common.by import By
  7. import random
  8. from random import choice
  9. from time import sleep, time
  10. import requests, csv, sys, zipfile, json, email, imaplib, re
  11. import faker
  12. fake_names = faker.Faker()
  13. COUNTRY = "CN" #CN, GB, US
  14.  
  15. WINDOW_X, WINDOW_Y = 1100, 800
  16.  
  17.  
  18. def my_proxy(PROXY_HOST,PROXY_PORT, username, password): # PROXY_HOST,PROXY_PORT
  19. if username:
  20. manifest_json = """
  21. {
  22. "version": "1.0.0",
  23. "manifest_version": 2,
  24. "name": "Chrome Proxy",
  25. "permissions": [
  26. "proxy",
  27. "tabs",
  28. "unlimitedStorage",
  29. "storage",
  30. "<all_urls>",
  31. "webRequest",
  32. "webRequestBlocking"
  33. ],
  34. "background": {
  35. "scripts": ["background.js"]
  36. },
  37. "minimum_chrome_version":"22.0.0"
  38. }
  39. """
  40.  
  41. background_js = """
  42. var config = {
  43. mode: "fixed_servers",
  44. rules: {
  45. singleProxy: {
  46. scheme: "http",
  47. host: '%s',
  48. port: parseInt('%s')
  49. },
  50. bypassList: ["foobar.com"]
  51. }
  52. };
  53.  
  54. chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
  55.  
  56. function callbackFn(details) {
  57. return {
  58. authCredentials: {
  59. username: '%s',
  60. password: '%s'
  61. }
  62. };
  63. }
  64.  
  65. chrome.webRequest.onAuthRequired.addListener(
  66. callbackFn,
  67. {urls: ["<all_urls>"]},
  68. ['blocking']
  69. );
  70. """% (PROXY_HOST, PROXY_PORT, username, password)
  71.  
  72. pluginfile = 'proxy_auth_plugin.zip'
  73.  
  74. with zipfile.ZipFile(pluginfile, 'w') as zp:
  75. zp.writestr("manifest.json", manifest_json)
  76. zp.writestr("background.js", background_js)
  77.  
  78. co = Options()
  79. co.add_argument("--start-maximized")
  80. co.add_extension(pluginfile)
  81. else:
  82. co = webdriver.ChromeOptions()
  83. co.add_argument('--proxy-server=%s' % PROXY_HOST+":"+PROXY_PORT)
  84.  
  85. co.add_argument('--disable-gpu')
  86. co.add_argument('--log-level=3')
  87. #co.add_argument('--headless')
  88. co.add_experimental_option("prefs", {"profile.managed_default_content_settings.images":2})
  89.  
  90. driver = webdriver.Chrome("C:/python/chromedriver.exe", chrome_options=co)
  91. return driver
  92.  
  93. _WebDriverWait = WebDriverWait
  94. def WebDriverWait(driver, time):
  95. try:
  96. error_view = driver.find_element_by_xpath("//div[@id='nike-unite-error-view']")
  97. except:
  98. return _WebDriverWait(driver, time)
  99. else:
  100. if error_view.is_displayed():
  101. raise NameError("Communication error.")
  102. else:
  103. return _WebDriverWait(driver, time)
  104.  
  105. def main(USERNAME, PASSWORD, count, total):
  106. while True:
  107. check=0
  108.  
  109. try:
  110. base_url = 'https://www.nike.com/%s/launch/' %COUNTRY.lower()
  111. proxy_list = []
  112. fname = fake_names.name().split(' ')[0]
  113. lname = fake_names.name().split(' ')[1]
  114.  
  115. if len(proxy_list) > 0:
  116. proxy = choice(proxy_list) # random choice of proxy
  117. split = proxy.split(':')
  118. proxy_host, proxy_port = split[0], split[1]
  119. if len(split) != 2:
  120. username, password = split[2], split[3]
  121. else:
  122. username, password = False, False
  123. driver = my_proxy(proxy_host, proxy_port, username, password)
  124. else:
  125. co = webdriver.ChromeOptions()
  126. co.add_argument('--disable-gpu')
  127. co.add_argument('--log-level=3')
  128. #co.add_argument('--headless')
  129. co.add_experimental_option("prefs", {"profile.managed_default_content_settings.images":2})
  130.  
  131. driver = webdriver.Chrome("C:/python/chromedriver.exe", chrome_options=co)
  132.  
  133. driver.set_window_size(WINDOW_X, WINDOW_Y)
  134.  
  135. driver.get(base_url) # browser gets the url
  136.  
  137. start = int(time())
  138.  
  139. 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/',
  140. '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/',
  141. '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/'])
  142.  
  143. 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", " " ))]'
  144. 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'])
  145. postcode = str(random.randint(000000, 999999))
  146. phone = '1'+ str(random.randint(0000000000, 9999999999))
  147.  
  148. try:
  149. WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, "//*[text()='Yes, I Accept']"))).click()
  150. except:
  151. pass
  152. sleep(5)
  153. 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()
  154. sleep(2)
  155. WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, "//*[text()='使用电子邮件登录。']"))).click()
  156.  
  157.  
  158.  
  159. WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, '//input[@type="email"]'))).send_keys(user)
  160. WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, '//input[@type="password"]'))).send_keys(pwd)
  161. WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, '//div/input[@type="button"]'))).click()
  162. sleep(5)
  163. driver.get(shoe_choice)
  164. sleep(5)
  165. WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, "//*[text()='尺码 ']"))).click()
  166.  
  167. WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, size_choice))).click()
  168. sleep(5)
  169. WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, "//*[text()='加入购物车']"))).click()
  170. sleep(20)
  171. WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, '//*[contains(concat( " ", @class, " " ), concat( " ", "jewel-cart-container", " " ))]'))).click()
  172. sleep(10)
  173. check=1
  174. WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, '//*[(@id = "ch4_cartCheckoutBtn")]'))).click()
  175. sleep(10)
  176. try:
  177. WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[(@id = "lname")]'))).send_keys(lname)
  178. WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[(@id = "fname")]'))).send_keys(fname)
  179.  
  180. WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[contains(concat( " ", @class, " " ), concat( " ", "js-state", " " ))]'))).click()
  181. sleep(2)
  182. WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="province"]/div/div/select/option[15]'))).click()
  183. WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[contains(concat( " ", @class, " " ), concat( " ", "js-city", " " ))]'))).click()
  184.  
  185. WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="city"]/div/div/select/option[8]'))).click()
  186.  
  187. WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="district"]/option[3]'))).click()
  188.  
  189. WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[contains(concat( " ", @class, " " ), concat( " ", "js-address1", " " ))]'))).send_keys(addy)
  190.  
  191. WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[(@id = "postalCodeField")]'))).send_keys(postcode)
  192.  
  193.  
  194. WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[(@id = "phoneNumber")]'))).send_keys(phone)
  195.  
  196. sleep(10)
  197.  
  198.  
  199. WebDriverWait(driver, 1).until(EC.element_to_be_clickable((By.XPATH, '//*[(@id = "shippingSubmit")]'))).click()
  200. except:
  201. pass
  202.  
  203. sleep(10)
  204. try:
  205.  
  206. WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, '//*[(@id = "individualName")]'))).send_keys(lname)
  207.  
  208. except:
  209. pass
  210.  
  211. WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, '//*[contains(concat( " ", @class, " " ), concat( " ", "ch4_btnPlaceOrder", " " ))]'))).click()
  212.  
  213.  
  214. sleep(30)
  215.  
  216. driver.quit()
  217. except Exception as s:
  218. print (s)
  219. driver.quit()
  220. if check==1:
  221. break
  222. else:
  223. driver.quit()
  224. print('Successfull ' + user)
  225. if check==1:
  226. break
  227.  
  228. if __name__ == '__main__':
  229. accounts = [line.rstrip('\n') for line in open('accounts.txt')]
  230. count = 1
  231.  
  232.  
  233. for user in accounts:
  234. spt = user.split(":")
  235. user = spt[0]
  236. pwd = spt[1]
  237.  
  238.  
  239. try:
  240. main(user,pwd, count,len(accounts))
  241. except Exception as e:
  242. print ("An error occurred: %s" %(e))
  243.  
  244. count += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement