def solve_captcha(s, image_url, session, thread_index): logger = s.logger imagefilepath = s.join_path( 'images/san_captcha_{}.jpg'.format(thread_index)) if os.path.exists(imagefilepath): os.remove(imagefilepath) r = session.get(image_url) # print "+++++++++++++Cookie++++++++++" # for c in r.cookies: # print(c.name, c.value) if r.status_code == 200: with open(imagefilepath, 'wb') as f: for chunk in r: f.write(chunk) captcha = CaptchaUpload(config.CPATHA_API_KEY) first_captcha_code = captcha.solve(imagefilepath) if str(first_captcha_code) == "1": logger.info("Captcha Service Error") return config.ERROR_NO_CAPTCHA logger.info('{} 1st_captcha2 -> {}'.format(prefix_letter(thread_index), first_captcha_code)) wait() return first_captcha_code
def upvote(voteNumber, voteLink, captchaToken): try: logger.log_text(f"Pushing Vote {voteNumber + 1}") driver = driver_init(voteLink) logger.log_text(f"Solving Captcha for vote {voteNumber + 1}") logging.getLogger().setLevel(logging.INFO) captcha = CaptchaUpload(captchaToken, log=logging) logger.log_text("Fetching captcha image from page") images = driver.find_elements_by_css_selector("img[border='0']") src = "" for image in images: if 'button' in image.get_attribute('src'): src = image.get_attribute('src') print(src) break logger.log_text("Generating UUID for captcha image") id = uuid.uuid1() logger.log_text("Saving captcha image") urllib.request.urlretrieve(src, f"captcha{id}.png") result = captcha.solve(f"captcha{id}.png") logger.log_text(f"Entering solved captcha result {result}") driver.find_element_by_name('confckno').click() driver.find_element_by_name('confckno').send_keys(result) driver.find_element_by_css_selector("input[type='submit']").click() except Exception as e: logger.log_header(e) finally: try: os.remove(f"captcha{id}.png") driver.quit() except Exception as e: logger.log_header(e)
def bypass_captcha(web): # bypass captcha logger.info("Bypassing captcha") x = 0 apikey = settings.apikey while True: try: image_element = web.find_element_by_xpath( "//img[@src='/scripts/srf/intercepta/captcha.aspx?opt=image']") except Exception: logger.info("Web server error: captcha not located") return False location = image_element.location size = image_element.size take_screenshot("captcha.png") crop_image(location, size) #solver = CaptchaSolver('antigate', api_key=apikey) # raw_data = open('captcha.png', 'rb').read() # text = solver.solve_captcha(raw_data) captcha = CaptchaUpload(apikey) text = captcha.solve('captcha.png') try: txtbox1 = web.find_element_by_id('idLetra') txtbox1.send_keys(text) except Exception: logger.info("Web server error") return False time.sleep(2) # submit web.find_element_by_name('Submit').click() time.sleep(5) try: # if captcha still there, need to try again image_element = web.find_element_by_xpath( "//img[@src='/scripts/srf/intercepta/captcha.aspx?opt=image']") logger.info("captcha error") x += 1 if x > 3: return False except Exception: return True
def captcha_solver(driver): captcha_src = driver.find_element_by_id( 'recaptcha_challenge_image').get_attribute("src") urllib.urlretrieve(captcha_src, "captcha.jpg") captcha = CaptchaUpload( "4cfd308fd703d40291a7e250d743ca84") # 2captcha API KEY captcha_answer = captcha.solve("captcha.jpg") wait = WebDriverWait(driver, 10) captcha_input_box = wait.until( EC.presence_of_element_located((By.ID, "recaptcha_response_field"))) captcha_input_box.send_keys(captcha_answer) driver.implicitly_wait(5) captcha_input_box.submit()
def parse(self): with open('cnpj_list.csv', 'rb') as f: csv_reader = csv.reader(f) item_list = list(csv_reader) for row in item_list: cnpj = row[0] self.driver.get(data_url) try: os.remove("captcha.jpg") except: pass sleep(1) img = self.driver.find_element_by_xpath("//img[@id='imgCaptcha']") self.get_captcha(self.driver, img, "captcha.jpg") captcha = CaptchaUpload(captcha_api_key) captcha_code = captcha.solve('captcha.jpg') captcha_code_old = captcha_code WebDriverWait(self.driver, 30).until( AnyEc( EC.presence_of_element_located( (By.XPATH, '//input[@id="cnpj"]')), EC.presence_of_element_located( (By.XPATH, '//input[@id="txtTexto_captcha_serpro_gov_br"]')))) self.driver.find_element_by_id('cnpj').send_keys(cnpj) self.driver.find_element_by_id( 'txtTexto_captcha_serpro_gov_br').send_keys(captcha_code_old) sleep(1) self.driver.find_element_by_id('submit1').click() WebDriverWait(self.driver, 30).until( EC.presence_of_element_located( (By.XPATH, "//span[@class='Rodape']"))) html_doc = Doc(html=self.driver.page_source) self.parse_detail(html_doc) self.driver.quit()
def __init__(self, user, password, name, api2captcha): self.s = requests.Session() self.s.headers.update(headers) self.user = user self.password = password self.name = name self.s.cookies = LWPCookieJar('cookiejar') self.captcha = CaptchaUpload((api2captcha)) self.hash_session = '' self.RequestVerificationToken = '' self.TokenData = '' self.TaiKhoanTrichNo = '' self.MaLoaiTaiKhoanEncrypt = '' self.SoDuHienTai = '' self.LoaiTaiKhoan = '' self.LoaiTienTe = '' self.AID = '' self.HinhThucChuyenTien = '' self.SoDuTaiKhoanNguon = '' self.LINK_DETAIL = '' self.otpValidType = '' self.captcha_guid1 = '' self.RequestVerificationData = ''
otvet = browser.find_element_by_xpath( "/html/body/div/div/div[2]/div/main/div/div/div/form/div[3]/div/div[1]/div[2]/span/input" ) cptch = browser.find_element_by_xpath( "/html/body/div/div/div[2]/div/main/div/div/div/form/div[3]/div/div[2]/div[1]/span/input" ) otvet.send_keys("privet") time.sleep(2) with open('filename.png', 'wb') as file: file.write( browser.find_element_by_xpath( '/html/body/div/div/div[2]/div/main/div/div/div/form/div[3]/div/div[2]/div[2]/div/div[1]/img' ).screenshot_as_png) captcha = CaptchaUpload("551835801dd0bedd0f97d7ebf358b2c7") answ = captcha.solve("filename.png") os.remove("filename.png") b = int(b) + 1 if answ == "1": print("Не удалось получить капчу") else: cptch.send_keys(answ) reg.click() f = open('mail.txt', 'w') f.write(name_r) f.write("@yandex.ru:") f.write(pasw_r)
) def get_captcha(): element = driver.find_element_by_id( "imgCaptcha") # element name containing the catcha image location = element.location size = element.size driver.save_screenshot("temp.png") x = location['x'] y = location['y'] w = size['width'] h = size['height'] width = x + w height = y + h im = Image.open('temp.png') im = im.crop((int(x), int(y), int(width), int(height))) im.save(captcha_fn) get_captcha() captcha = CaptchaUpload("hvxrw69kkdcpfzjt38jtm2bxyzr7ypvn") captcha_resolved = captcha.solve(captcha_fn) driver.find_element_by_id("captcha").send_keys(captcha_resolved) driver.find_element_by_xpath( '//*[@id="container_captcha"]/fieldset/table/tbody/tr[2]/td[2]/input' ).click()
from scrapex import * import time import sys import csv import re, random, base64 import json # import MySQLdb as mdb import pymysql as mdb from captcha2upload import CaptchaUpload from datetime import datetime import urllib import pytz import os.path import os captcha_api_key = "3124db5dec29ab4024f2a7357889651a" if __name__ == '__main__': # logger = logger # lasd_url = 'http://app5.lasd.org/iic/' # print lasd_url captcha = CaptchaUpload(captcha_api_key) captcha_code = captcha.solve('captcha2.png') print captcha_code # captcha = CaptchaUpload(captcha_api_key) # print captcha.getbalance()
class vbc_task(): def __init__(self, user, password, name, api2captcha): self.s = requests.Session() self.s.headers.update(headers) self.user = user self.password = password self.name = name self.s.cookies = LWPCookieJar('cookiejar') self.captcha = CaptchaUpload((api2captcha)) self.hash_session = '' self.RequestVerificationToken = '' self.TokenData = '' self.TaiKhoanTrichNo = '' self.MaLoaiTaiKhoanEncrypt = '' self.SoDuHienTai = '' self.LoaiTaiKhoan = '' self.LoaiTienTe = '' self.AID = '' self.HinhThucChuyenTien = '' self.SoDuTaiKhoanNguon = '' self.LINK_DETAIL = '' self.otpValidType = '' self.captcha_guid1 = '' self.RequestVerificationData = '' def vcb_login(self): try: r = self.s.get(url_login) if r.status_code == 200: content = r.text doc = lxml.html.fromstring(content) img_capchat = doc.xpath( "//div[@class='img-captcha']/img/@src")[0] response = self.s.get(url_vcb + img_capchat, stream=True) with open('captcha.png', 'wb') as out_file: shutil.copyfileobj(response.raw, out_file) del response captcha_id = doc.xpath( "//input[@name='captcha-guid1']/@value")[0] captcha_sm = self.captcha.solve(out_file.name) data = { 'source': '', 'username': str(self.user), 'pass': str(self.password), 'captcha': str(captcha_sm), 'captcha-guid1': str(captcha_id), } r = self.s.post(r.url, data=data, allow_redirects=True) if r.status_code == 200: doc = lxml.html.fromstring(r.text) self.hash_session = doc.xpath( "//li[@class='home']/a/@href")[0] self.RequestVerificationToken = doc.xpath( "//input[@name='__RequestVerificationToken']/@value" )[0] self.LINK_DETAIL = doc.xpath( "//a[@class='linkDetails icon-right']/@href")[0] return True else: return False else: return False except: return False def check_login(self): try: r = self.s.get(url_login) if r.status_code == 200: doc = lxml.html.fromstring(r.text) check = doc.xpath( "//div[@class='dieuhuong dieuhuong-home']/span/span/text()" )[0] self.hash_session = doc.xpath("//li[@class='home']/a/@href")[0] self.RequestVerificationToken = doc.xpath( "//input[@name='__RequestVerificationToken']/@value")[0] self.LINK_DETAIL = doc.xpath( "//a[@class='linkDetails icon-right']/@href")[0] else: return False except: return False if check == self.name: return True return False def data_detal(self, startdate, enddate): data = { 'TokenData': str(self.TokenData), '__RequestVerificationToken': str(self.RequestVerificationToken), 'TaiKhoanTrichNo': str(self.TaiKhoanTrichNo), 'MaLoaiTaiKhoanEncrypt': str(self.MaLoaiTaiKhoanEncrypt), 'SoDuHienTai': str(self.SoDuHienTai), 'LoaiTaiKhoan': str(self.LoaiTaiKhoan), 'LoaiTienTe': str(self.LoaiTienTe), 'AID': str(self.AID), 'NgayBatDauText': str(startdate), 'NgayKetThucText': str(enddate), } return data def get_data_infor(self): try: r = self.s.get(url_vcb + self.LINK_DETAIL) if r.status_code == 200: doc = lxml.html.fromstring(r.text) self.RequestVerificationToken = doc.xpath( "//input[@name='__RequestVerificationToken']/@value")[0] newstr = doc.xpath( "//select[@id='TaiKhoanTrichNo']/option/@value")[0] self.TaiKhoanTrichNo = newstr self.MaLoaiTaiKhoanEncrypt = newstr.split('|')[1] self.AID = doc.xpath("//input[@name='AID']/@value")[0] data = self.data_detal('', '') # print data # sau khi lay data lan moi duoc lay tokendata # self.hash_session = doc.xpath("//li[@class='home']/a/@href")[0] r = self.s.post( url_vcb + self.hash_session.replace("ibanking2015", "IBanking2015") + path_detail_info, data=data, allow_redirects=False) post_response = json.loads(r.text) # print post_response # print post_response['DanhSachTaiKhoan'] self.SoDuHienTai = int( post_response['DanhSachTaiKhoan'][0]['SoDuKhaDung']) self.LoaiTaiKhoan = post_response['DanhSachTaiKhoan'][0][ 'MaLoaiTaiKhoan'] self.LoaiTienTe = post_response['DanhSachTaiKhoan'][0][ 'LoaiTienTe'] self.TokenData = post_response['TokenData'] return True else: return False except: return False def detail_exchange(self, startdate, enddate): if self.get_data_infor() == False: return False data = self.data_detal(startdate, enddate) try: r = self.s.post(url_vcb + self.hash_session + path_detail_exchange, data=data, allow_redirects=False) if r.status_code == 200: post_response = json.loads(r.text) return post_response['ChiTietGiaoDich'] else: return False except: return False def check_namein(self, accountnb): # dict_cookies= requests.utils.dict_from_cookiejar(s.cookies) # for d in dict_cookies : # if regex.search(d): # self.RequestVerificationToken=dict_cookies.get(d) data = { 'SoTaiKhoan': str(accountnb), '__RequestVerificationToken': str(self.RequestVerificationToken), } try: r = self.s.post(url_vcb + self.hash_session + path_checknamein, data=data, allow_redirects=False) if r.status_code == 200: post_response = json.loads(r.text) return post_response['TenChuKhoan'] else: return False except: return False def data_send_money_step1(self, name_receiver, nb_receiver, amount, memo): data = { '__RequestVerificationToken': str(self.RequestVerificationToken), 'HinhThucChuyenTien': str(self.HinhThucChuyenTien), 'TaiKhoanTrichNo': str(self.TaiKhoanTrichNo.split('|')[0]), 'SoDuTaiKhoanNguon': str(self.SoDuHienTai), 'LoaiTienTaiKhoanNguon': str(self.LoaiTienTe), 'SoTaiKhoanNguoiHuong': str(nb_receiver), 'TenNguoiHuong': str(name_receiver), 'LuuThongTinNguoiHuong': 'false', 'TenGoiNho': '', 'SoTien': str(amount), 'LoaiTienChuyenKhoan': str(self.LoaiTienTe), 'NoiDungThanhToan': str(memo), 'ThuPhiNguoiChuyen': str(self.ThuPhiNguoiChuyen), } return data def send_money_step1(self, amount, nb_receiver, memo): try: self.HinhThucChuyenTien = 1 self.ThuPhiNguoiChuyen = 2 name_receiver = self.check_namein(nb_receiver) self.get_data_infor() data = self.data_send_money_step1(name_receiver, nb_receiver, amount, memo) r = self.s.post( url_vcb + self.hash_session.replace("ibanking2015", "IBanking2015") + path_send_money_step1, data=data, allow_redirects=True) if r.status_code == 200: post_response = json.loads(r.text) if post_response['Status']['Error'] == False: return True else: return False else: return False except: return False def data_send_money_step2(self, captcha_sm): data = { '__RequestVerificationToken': str(self.RequestVerificationToken), 'otpValidType': str(self.otpValidType), 'captcha-guid1': str(self.captcha_guid1), 'otpCaptcha': str(captcha_sm), } return data def send_money_step2(self): try: self.otpValidType = 3 r = self.s.get(url_vcb + self.hash_session + path_send_money) doc = lxml.html.fromstring(r.text) self.captcha_guid1 = doc.xpath( "//input[@name='captcha-guid1']/@value")[0] img_capchat = doc.xpath("//img[@id='captchaImage']/@src")[0] response = self.s.get(url_vcb + img_capchat, stream=True) with open('captcha.png', 'wb') as out_file: shutil.copyfileobj(response.raw, out_file) del response captcha_sm = captcha.solve(out_file.name) data = self.data_send_money_step2(captcha_sm) r = self.s.post( url_vcb + self.hash_session.replace("ibanking2015", "IBanking2015") + path_send_money_step2, data=data, allow_redirects=True) if r.status_code == 200: post_response = json.loads(r.text) if post_response['Status']['Error'] == False: self.RequestVerificationData = post_response['Status'][ 'ExtraData'] return True else: return False else: return False except: return False def data_send_money_step3(self, MaGiaoDich): data = { '__RequestVerificationToken': str(self.RequestVerificationToken), '_RequestVerificationData': str(self.RequestVerificationData), 'MaGiaoDich': str(MaGiaoDich), } return data def send_money_step3(self): # try: count = 0 while True or count == 5: f = open("text.txt", "r") check = f.read() if check != '': MaGiaoDich = check break time.sleep(6) count = count + 1 # lay ma giao dich tu database data = self.data_send_money_step3(MaGiaoDich) r = self.s.post( url_vcb + self.hash_session.replace("ibanking2015", "IBanking2015") + path_send_money_step3, data=data, allow_redirects=True) if r.status_code == 200: post_response = json.loads(r.text) if post_response['Error'] == False: return True else: return False else: return False except: return False def send_money(self, amount, nb_receiver, memo): if self.send_money_step1(amount, nb_receiver, memo) == True: print "Done Step 1" if self.send_money_step2() == True: print "Done Step 2" if self.send_money_step3() == True: print "Done Step 3" return True else: return False else: return False else: return False def main(self): if not os.path.exists('cookiejar'): self.s.cookies.save() else: self.s.cookies.load(ignore_discard=True) if self.check_login() != True: print "New Login" if self.vcb_login() != True: print "Login Fail" return False self.s.cookies.save(ignore_discard=True) return True
def SolveCaptha(driver): RandomName = str(randint(1000, 9999)) CaptchaFunc = CaptchaUpload('f4ab06a8e3e5be77134312d55c7a7bb4') time.sleep(5) # get captcha Image Image = False try: if 'Robot Check' in driver.title: Image = driver.find_element_by_tag_name('img').get_attribute('src') except: pass try: Image = driver.find_element_by_id("auth-captcha-image") except: pass if not Image: return True # download Image try: request.urlretrieve(Image, "./logs/" + RandomName + ".jpg") time.sleep(5) CaptchaAnswer = CaptchaFunc.solve("./logs/" + RandomName + ".jpg") except: print('Captcha fail to solve') return False finally: try: os.system("rm " + "./logs/" + RandomName + ".jpg") except: pass # fill captcha try: FillAnswer = driver.find_element_by_id("captchacharacters") except: pass try: FillAnswer = driver.find_element_by_id("auth-captcha-guess") except: pass try: FillAnswer.click() FillAnswer.clear() FillAnswer.send_keys(CaptchaAnswer) except: print('Captcha fail to fill') return False #submit captcha try: driver.find_element_by_id('continue').click() except: pass try: driver.find_element_by_xpath("//button[@type='submit']").click() except: pass try: driver.find_element_by_id("cnep_1B_submit_button").click() except: pass try: driver.find_element_by_id('signInSubmit').click() except: pass return True
getrequest = browser.open(get_url).read() getrequest = getrequest.split("timeout") getrequest = getrequest[0].split("challenge : '") getrequest = getrequest[1].split("',") #print getrequest[0] urlcaptcha = "http://www.google.com/recaptcha/api/image?c=" + getrequest[0] #print urlcaptcha nombredelarchivo = "asd.jpg" urllib.urlretrieve(urlcaptcha, nombredelarchivo) captcha = CaptchaUpload('4348b97c044925f5f1117cfea1f0e269') #print captcha.getbalance() captcha.solve(nombredelarchivo) captcharesuelto = captcha.solve(nombredelarchivo) captchachallenge = getrequest[0] #print captchachallenge #print captcharesuelto ####################################################### fin de resolucion de captcha ##################### Comienzo el metodo POST post_url = "http://www.bcra.gob.ar/Informacion_usuario/iaucen010001.asp" parametros = { 'CUIT':'20284619685',
#to open firefox driver = webdriver.Firefox() driver.implicitly_wait(30) driver.maximize_window() #Enter the url on which captcha is implemented..for now paste url here print ("Navigating to https://example.com") driver.get("https:example.com") print ("Finding the captcha image") #finding the captcha image on the page by its xpath..for now hardcode the xpath here captcha_img = driver.find_element_by_xpath("paste xpath here") #downloading the captcha from the source src = captcha_img.get_attribute('src') print (src) #saving the captcha image as captchanew.png urllib.urlretrieve(src, "captchanew.png") print("Identifying captcha characters") #close firefox driver.quit() #invoke the az captcha api captcha = CaptchaUpload("yourapikey") #api key of your azcaptcha account print captcha.solve("/path/to/save/image/captchanew.png") print ("Captcha characters identified")
def __init__(self, driver): self.driver = driver self.speed = 20 # page scroll speed self.captcha = CaptchaUpload('f4ab06a8e3e5be77134312d55c7a7bb4')
def AMAZONPackage(user, psswd): thread = [] trackingUrl = [] driver = webdriver.Firefox() driver.get( "https://www.amazon.com/ap/signin?_encoding=UTF8&ignoreAuthState=1&openid.assoc_handle=usflex&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.com%2F%3Fref_%3Dnav_signin&switch_account=" ) WebDriverWait(driver, 30).until( EC.presence_of_element_located((By.XPATH, "//input[@id='ap_email']"))) emailField = driver.find_element_by_xpath("//input[@id='ap_email']") passwordField = driver.find_element_by_xpath("//input[@id='ap_password']") emailField.send_keys(user) passwordField.send_keys(psswd) passwordField.send_keys(Keys.ENTER) try: WebDriverWait(driver, 5).until( EC.presence_of_element_located( (By.XPATH, "//input[@id='continue']"))) verificationbutton = driver.find_element_by_xpath( "//input[@id='continue']") verificationbutton.click() WebDriverWait(driver, 5).until( EC.presence_of_element_located( (By.XPATH, "//*[@id='cvf-page-content']/div/div/div[1]/form/div[2]/input" ))) t1 = threading.Thread(target=iothub_client_telemetry_sample_run) t1.start() thread.append(t1) thread[0].join(0) time.sleep(60) verificationCode = [] try: with open(r"verification.csv", mode="r", encoding="utf-8") as f: reader = csv.reader(f, delimiter=",") for row_index, row_data in enumerate(reader): verificationCode = row_data except: time.sleep(0.5) verificationbuttonInput = driver.find_element_by_xpath( "//*[@id='cvf-page-content']/div/div/div[1]/form/div[2]/input") verificationbuttonInput.send_keys(verificationCode[0]) submitVerification = driver.find_element_by_xpath( "//*[@id='a-autoid-0']/span/input") submitVerification.click() try: os.remove("verification.csv") except: None time.sleep(10) except: time.sleep(0.5) username = driver.find_element_by_xpath("//input[@id='ap_email']") imageCaptcha = driver.find_element_by_xpath( "//div[@id='auth-captcha-image-container']/img[@id='auth-captcha-image']" ).get_attribute("src") password = driver.find_element_by_xpath("//input[@id='ap_password']") username.clear() password.clear() username.send_keys(user) password.send_keys(psswd) r = requests.get(imageCaptcha) with open('imageCaptcha' + '.jpg', 'wb') as f: f.write(r.content) # solver = CaptchaSolver('twocaptcha', api_key='e84b10e0869becd360d0a4eb58460449') captcha = CaptchaUpload('e84b10e0869becd360d0a4eb58460449') # raw_data = open('imageCaptcha.jpg', 'rb').read() # print(solver.solve_captcha(raw_data)) captchaString = captcha.solve("imageCaptcha.jpg") captchaKey = driver.find_element_by_xpath( "//div[@class='a-section']/input[@id='auth-captcha-guess']") for x in captchaString: captchaKey.send_keys(x) time.sleep(random.randint(1, 4) / 5) # time.sleep(3) signupClick = driver.find_element_by_xpath( "//input[@id='signInSubmit']") signupClick.click() time.sleep(3) pass try: WebDriverWait(driver, 30).until( EC.presence_of_element_located( (By.XPATH, "//*[@id='nav-orders']"))) except: return orderInfo = driver.find_element_by_xpath("//*[@id='nav-orders']") orderInfo.click() try: WebDriverWait(driver, 30).until( EC.presence_of_element_located(( By.XPATH, "//div[@class='a-box-inner']/div/div/div[@class='a-row']/div/span/span/span/a" ))) except: None try: for i in range(100): try: WebDriverWait(driver, 30).until( EC.presence_of_element_located(( By.XPATH, "//div[@class='a-box-inner']/div/div/div[@class='a-row']/div/span/span/span/a" ))) except: break trackUrlElements = driver.find_elements_by_xpath( "//div[@class='a-box-inner']/div/div/div[@class='a-row']/div/span/span/span/a" ) for trackUrlElement in trackUrlElements: trackingUrl.append(trackUrlElement.get_attribute("href")) try: nextButton = buttons[len(buttons) - 1] nextButton.click() buttons = driver.find_elements_by_xpath( "//*[@id='ordersContainer']/div/div/ul/li/a") time.sleep(1) except: break except: None df4 = [] for trancking in trackingUrl: driver.get(trancking) WebDriverWait(driver, 30).until( EC.presence_of_element_located( (By.XPATH, "//*[@id='primaryStatus']"))) time.sleep(1.8) try: trackingid = driver.find_element_by_xpath( "//*[@id='carrierRelatedInfo-container']/div/span/a" ).text.split(":")[1][:-1] except: continue order = driver.find_element_by_xpath("//*[@id='primaryStatus']").text status = order.split(" ")[0] orderDate = order.replace(status, "") if status == "Delivered": print(['AMAZON', status, orderDate, trackingid]) continue with open('myfile-1.csv', "a", encoding="utf-8", newline="") as f: writer = csv.writer(f, delimiter=',') writer.writerow(['AMAZON', status, orderDate, trackingid]) print(['AMAZON', status, orderDate, trackingid]) driver.close() driver.quit()
def solveCap(path): key = 'b727fcc73349f3ed88be668d0010903d' captcha = CaptchaUpload(key) urllib.request.urlretrieve(path, "captcha.jpg") return captcha.solve('captcha.jpg')