def amil_code(self, dr, amil_num, login_wd): # 翻页后获得验证码输入框并输入 vir = dr.find_element_by_xpath( '//*[@id="cvf-page-content"]/div/div/div[1]/form/div[2]/input') amil_wd = self.data_tool.get_reg_info('amil_wd', self.info_id) vir_code = get_vir_code(amil_num, amil_wd) if vir_code == 1: self.data_tool.update_info(2, '邮箱验证失败!', self.info_id) dr.quit() return else: vir.send_keys(vir_code) verifiter = dr.find_element_by_xpath('//*[@id="a-autoid-0"]') verifiter.click() html = dr.page_source name = self.data_tool.get_name(self.info_id) firstname = name.split(' ')[0] bonjour_name = 'Hello, ' + firstname if bonjour_name in html: # 更新用户状态码 self.data_tool.update_info(1, login_wd, self.info_id) cookies = dr.get_cookies() with open("cookies.txt", "w") as fp: json.dump(cookies, fp) self.data_tool.update_cookies(self.info_id) time.sleep(1) input_kw = dr.find_element_by_xpath( '//*[@id="twotabsearchtextbox"]') key_word = make_data.get_kw() input_kw.send_keys(key_word) sub = dr.find_element_by_xpath( '//*[@id="nav-search"]/form/div[2]') sub.click() # wait.until(EC.presence_of_element_located((By.ID, 'a-page'))) num = 0 try: detail_node = dr.find_element_by_xpath( '//*[@id="search"]/div[1]/div[2]/div/span[3]/div[1]/div[1]//h5/a' ) detail_node.click() except: print('获取商品详情页面失败') finally: self.like_car(dr) else: self.data_tool.update_info(2, "邮箱已使用!", self.info_id) time.sleep(1) dr.quit() return
def login(self, y, x): chrome_options = getproxy_uk.getpro() dr = webdriver.Chrome(options=chrome_options) dr.set_page_load_timeout(70) dr.set_window_size(300, 300) dr.set_window_position(y=y, x=x) url = 'https://www.amazon.co.uk/ap/signin?_encoding=UTF8&ignoreAuthState=1&openid.assoc_handle=gbflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.co.uk%2F%3Fref_%3Dnav_signin&switch_account=' dr.get(url) try: if 'Sign in' in dr.page_source: amil = dr.find_element_by_id('ap_email') amil_code = self.data_tool.get_reg_info( 'amil_num', self.info_id) amil.send_keys(amil_code) wd = dr.find_element_by_id('ap_password') # wd_code = self.data_tool.get_reg_info('login_wd', self.info_id) wd_code = amil_code[:5] + '123' wd.send_keys(wd_code) remember = dr.find_element_by_name('rememberMe') remember.click() login = dr.find_element_by_id('signInSubmit') login.click() firstname = self.data_tool.get_name(self.info_id).split(' ')[0] if firstname in dr.page_source: self.save_cookies(dr, wd_code) info1 = 'Thank you' info2 = 'Verification needed' if info2 in dr.page_source: sub = dr.find_element_by_id('continue') sub.click() amil_info = dr.find_element_by_name('code') amil_wd = self.data_tool.get_reg_info( 'amil_wd', self.info_id) vir_code = get_vir_code(amil_code, amil_wd) amil_info.send_keys(vir_code) sub = dr.find_element_by_class_name('a-button-input') sub.click() if firstname in dr.page_source: self.save_cookies(dr, wd_code) if info1 in dr.page_source: name = dr.find_element_by_name('dcq_question_subjective_1') name_wd = self.data_tool.get_name(self.info_id) name.send_keys(name_wd) sub = dr.find_element_by_name('cvfDcqAction') sub.click() if firstname in dr.page_source: self.save_cookies(dr, wd_code) return except: # self.data_tool.update_state(self.info_id) dr.quit() return
def amil_code(self, dr, amil_num, login_wd): # 翻页后获得验证码输入框并输入 vir = dr.find_element_by_xpath('//*[@id="cvf-page-content"]/div/div/div[1]/form/div[2]/input') amil_wd = self.data_tool.get_reg_info('amil_wd', self.info_id) vir_code = get_vir_code(amil_num, amil_wd) if vir_code == 1 or vir_code == 0: self.data_tool.update_info(2, '邮箱验证失败!', self.info_id) dr.quit() return else: vir.send_keys(vir_code) verifiter = dr.find_element_by_xpath('//*[@id="a-autoid-0"]') verifiter.click() html = dr.page_source name = self.data_tool.get_name(self.info_id) firstname = name.split(' ')[0] # bonjour_name = 'Ciao, ' + firstname ' Anton...さん' ' Avaさん' if len(firstname) > 5: bonjour_name = firstname[:5] + "..." + 'さん' elif len(firstname) == 5: bonjour_name = firstname + 'さん' else: bonjour_name = firstname + 'さん' print(bonjour_name) if bonjour_name in html: # 更新用户状态码 self.data_tool.update_info(1, login_wd, self.info_id) cookies = dr.get_cookies() with open("cookies.txt", "w") as fp: json.dump(cookies, fp) self.data_tool.update_cookies(self.info_id) time.sleep(1) input_kw = dr.find_element_by_xpath('//*[@id="twotabsearchtextbox"]') key_word = make_data.get_kw_jp() input_kw.send_keys(key_word) sub = dr.find_element_by_xpath('//*[@id="nav-search"]/form/div[2]/div') sub.click() try: detail_node = dr.find_element_by_xpath( '//*[@id="search"]/div[1]/div[2]/div/span[3]/div[1]/div[1]//h5/a') detail_node.click() except: print('获取商品详情页面失败') finally: self.like_car(dr, amil_num) # if key_word == 'Skirt': else: self.data_tool.update_info(2, "邮箱已使用!", self.info_id) time.sleep(1) dr.quit() return