def process(country, numOfAdults, numOfInfants, numOfChildren, fromDate, toDate): start = time.time() airbnb.initialize() r.wait() #airbnb.select_stay() #r.wait() airbnb.close_cookie_popup() airbnb.enter_country_city(country) airbnb.enter_dates(fromDate,toDate) #airbnb.enter_personnel(2,2,1) airbnb.enter_personnel(numOfAdults,numOfInfants,numOfChildren) airbnb.click_search() r.wait() #airbnb.recreate_temp() airbnb.snap_map() data = airbnb.extract_stay_info_as_data() print("Sending Date back to controller") print(data) r.close() end = time.time() elapsed = end - start print(f'Time Elapsed: {elapsed} seconds') response = data return response
def download_stay_picinfo(): #Downloads picture locally as jpg img, MIGHT be useful if we are doing local image classification....but I rather gcloud classify with url if needed print('Extracting Top 5 Stay Information..') url=[] url=get_stay_url() print('Downloading Pics uploaded by host..') i=0 k=0 while (i<5): r.url(url[i+k]) r.click('//*[@id="FMP-target"]') j=0 while (1): j=j+1 print(f'Downloading Homestay {i+1} Photo {j}') r.wait(0.4) #r.snap('//div[@data-testid="photo-viewer-slideshow-desktop"]/div/div/div/div/div/img',f"data/{i+1}/{j}.jpg") #fastest but not perfect if (r.exist('//div[@data-testid="photo-viewer-slideshow-desktop"]/div/div/div/div/div/img/@src') == True): dl_link=r.read('//div[@data-testid="photo-viewer-slideshow-desktop"]/div/div/div/div/div/img/@src') r.download(dl_link,f'data/{i+1}/{j}.jpg') print(f'Homestay {i+1} Photo {j} downloaded!') else: i=i-1 #Detects Whales (Airbnb Plus spoils the format alot) k=k+1 #Compensating Constant k print("WHALE detected, adding one more loop..") if (r.exist('/html/body/div[9]/div/div/div/div/div[3]/div/div[2]/button') == False or j >= 15): break #Max 15 photos r.click('/html/body/div[9]/div/div/div/div/div[3]/div/div[2]/button') i=i+1 r.click('/html/body/div[9]/div/div/div/section/div/div[1]/div/button') print('Done.')
def main(): r.init() r.url('https://www.hattrick.org/zh/') r.type('ctl00_CPContent_ucLogin_txtUserName', 'ccforever') r.type('ctl00_CPContent_ucLogin_txtPassword', 'cc0323') r.click('ctl00_CPContent_ucLogin_butLogin') r.wait('10') r.click('myClubLink')
def login(): # GG CAPTCHA (abandoned ship) r.click('//header[@role="banner"]/div/div/div[3]/div/div/nav/ul/li[6]') r.wait(10) if r.present('//div[@aria-label="Log in"]/div[2]/div[4]/button') == True: # Anti RPA by AirBnB r.click('//div[@aria-label="Log in"]/div[2]/div[4]/button') if r.present('//button[@data-testid="social-auth-button-email"]') == True: # Anti RPA by AirBnB r.click('//button[@data-testid="social-auth-button-email"]') r.type('//*[@id="email"]', USERNAME) r.type('//*[@id="password"]', PASSWORD) r.click('//button[@data-veloute="submit-btn-cypress"]') r.click('//*[@id="recaptcha-anchor"]/div[1]')
def convert_html_to_jpg(): URL = "http://127.0.0.1:5000/get_html" #localhost r.init() r.url(URL) print('Zooming out') r.click('//*[@class="leaflet-control-zoom-out"]') r.click('//*[@class="leaflet-control-zoom-out"]') print('Waiting to load...') r.wait(18) print('Snapping') r.snap('//html/body', "./Images/map.jpg") print('Done.') r.close()
def main(): url = 'http://rpachallenge.com' accessible_url = connection_url_verify(url) if accessible_url: web_page_init(url) else: print("Bye.") r.wait(2) workbook = download_workbook(file_name='workbook.xlsx') op_workbook = open_workbook(workbook) data_frame = workbook_df(op_workbook) labels_list = lb_list() start_challenge(data_frame, labels_list) end_challenge()
def gestionar_uuii(uuii, codigoPostal, cto): r.url(uuii) r.timeout(120) if r.read('//*[@id="btnNew"]'): r.click('//*[@id="btnNew"]') r.timeout(120) if r.read('//*[@id="btnFormEditSave"]'): r.select('//*[@name="planta"]', 'BA') r.type('//*[@name="cp"]', codigoPostal) r.click('//*[@id="btnFormEditSave"]') if r.read('//*[@class="tableCell"]'): r.click('//*[@class="tableCell"]') r.click('//*[@id="btnRD"]') if r.read('//*[@id="btnFormRDSave"]'): r.timeout(120) r.select('//*[@name="rd"]', cto) r.wait(5) if r.read('//*[@id="ctoAddress_ctoName"]'): r.click('//*[@id="btnFormRDSave"]') if r.url('xxxx.do?dispatchMethod=rdSave'): print('Gestionada')
def login(): r.init(visual_automation=True, chrome_browser=False) r.run('E:\soft_isruning_position\WXWork\WXWork.exe') r.click("h.jpg") r.click("3.png") r.wait(1.5) is_true = r.exist("aa.png") print(is_true) if is_true: r.snap( "step-6.png", filename_to_save= r"D:\projects\S_Git_proj\spider\Other\spider_all\Rpa-Python\image") print("截图") print("进行图片传输") r.wait(1.5) is_true = r.exist('step-1.png') if is_true: print("login success") else: print("login fail")
def process(country, numOfAdults, numOfInfants, numOfChildren, fromDate, toDate): start = time.time() airbnb.initialize() r.wait() airbnb.select_stay() r.wait() airbnb.enter_country_city(country) airbnb.close_cookie_popup() r.wait() airbnb.enter_dates(fromDate,toDate) r.wait() #adult, infant, child #airbnb.enter_personnel(1,2,3) airbnb.enter_personnel(numOfAdults,numOfInfants,numOfChildren) #airbnb.recreate_temp() airbnb.snap_map() data = airbnb.extract_stay_info_as_data() print("Sending Date back to controller") print(data) r.close() end = time.time() elapsed = end - start print(f'Time Elapsed: {elapsed} seconds') response = """ Country : {0} Num: {1} From: {2} To: {3} """.format(country, numOfPeople, fromDate, toDate) return response
def end_challenge(): r.snap('page', 'registry.png') r.wait(1) r.close()
def b2wRegister(cnpj, loginEmail, customerName, customerCpf, customerPhone, customerPosition, site, mei, registrationState): r.init() r.url('https://www.b2wmarketplace.com.br/v3/registre-se') p.sleep(15) p.sleep(3) # page1 # cnpj r.type( '/html/body/app-root/div/app-signup/main/section[2]/div/div/div/form[1]/div/div[1]/div/input', str(cnpj)) # loginEmail r.type( '/html/body/app-root/div/app-signup/main/section[2]/div/div/div/form[1]/div/div[2]/div/input', str(loginEmail)) r.wait(5.0) p.screenshot('b2wCadastroPrimeiraParte.png') r.wait(3.0) # submit r.click( '//*[@id="main"]/app-signup/main/section[2]/div/div/div/form[1]/div/div[4]/button' ) r.click( '//*[@id="main"]/app-signup/main/section[2]/div/div/div/form[1]/div/div[4]/button' ) r.wait(5.0) # page2 if mei == True: # click checkbox mei r.click( '//*[@id="main"]/app-signup/main/section[2]/div/div/div/form[2]/div/div[2]/div/div/div/input' ) else: #inscriçãoEstadual r.type( '//*[@id="main"]/app-signup/main/section[2]/div/div/div/form[2]/div/div[2]/div/div/input', str(registrationState)) # customerName r.type( '//*[@id="main"]/app-signup/main/section[2]/div/div/div/form[2]/div/div[3]/div/input', str(customerName)) ''' for tribo urbana, client role never will be: 'Colaborador(a) da Empresa' only: owner or partner so, do not need a conditional for input 'Colaborador(a) da Empresa' role ''' # customerPosition r.type( '//*[@id="main"]/app-signup/main/section[2]/div/div/div/form[2]/div/div[4]/div/select', str(customerPosition)) # customerCpf r.type( '//*[@id="main"]/app-signup/main/section[2]/div/div/div/form[2]/div/div[6]/div/input', str(customerCpf)) # customerPhone r.type( '//*[@id="main"]/app-signup/main/section[2]/div/div/div/form[2]/div/div[8]/div/input', str(customerPhone)) # site r.type( '//*[@id="main"]/app-signup/main/section[2]/div/div/div/form[2]/div/div[7]/div/input', str(site)) p.screenshot('b2wCadastroSegundaParte.png') # submit r.click( '//*[@id="main"]/app-signup/main/section[2]/div/div/div/form[2]/div/div[11]/button' ) p.sleep(10) #read email, get code and confirm readEmailToHtml() p.sleep(12) p.hotkey('alt', 'tab') p.sleep(1) # clickEmailCodeInput() r.click('//*[@id="confirmEmail"]/div/div/div[2]/div/div/input') r.click('//*[@id="confirmEmail"]/div/div/div[2]/div/div/input') r.type('//*[@id="confirmEmail"]/div/div/div[2]/div/div/input', str(emailCodeB2w())) p.sleep(3) # p.write(codeEmailB2w()) p.sleep(3) # clickEmailCodeConfirm() r.click('//*[@id="confirmEmail"]/div/div/div[3]/div[2]/button') r.click('//*[@id="confirmEmail"]/div/div/div[3]/div[2]/button') r.wait(10.0) p.screenshot('b2wTerceiraParte.png') r.wait(1.0) r.close()
def web_page_init(url): r.init() r.wait(2.0) r.url(webpage_url=url)
r.init() workbook = xlsxwriter.Workbook('İhale.xlsx') worksheet = workbook.add_worksheet() worksheet.set_column('B:B', 100) worksheet.set_column('C:C', 75) worksheet.set_column('D:D', 25) worksheet.write('B1', 'İhale Adı') worksheet.write('C1', 'İdare Adı') worksheet.write('D1','İhale Onaylanma Tarihi') r.url('https://ekap.kik.gov.tr/EKAP/Ortak/IhaleArama/index.html') r.wait(8) r.click('/html/body/div/div[1]/div/div/div[4]/div[2]/input') r.type('/html/body/div/div[1]/div/div/div[4]/div[2]/input','bilgisayar') r.wait(1) r.click('/html/body/div/div[1]/div/div/div[4]/div[4]/div[3]/select') r.wait(1) r.type('/html/body/div/div[1]/div/div/div[4]/div[4]/div[3]/select','i') r.wait(1) r.click('pnlFiltreBtn') r.wait(3) total_items = r.count('div.col-sm-12') print("Toplam İhale Sayısı =",total_items) r.wait(3)
import rpa as r import csv r.init(visual_automation=True) # use url('your_url') to go to web page, url() returns current URL r.url('http://rpachallenge.com/') r.wait(5.1) r.hover('imagesstart.png') # mover mouse para o botao start r.click('images/start.png') # clicar no botao start def scroll_down(): r.hover('imagesarrow-down.png') r.click('images/arrow-down.png') r.click('images/arrow-down.png') r.click('images/arrow-down.png') def scroll_up(): r.hover('imagesarrow-up.png') r.click('images/arrow-up.png') r.click('images/arrow-up.png') r.click('images/arrow-up.png') def read_and_iterate_csv(): with open('persons.csv', 'r') as file: inputfile = csv.reader(file) next(inputfile) # pular cabecalhos ['nome','signo','email','endereco',
import rpa as r import pyautogui as p r.init() r.url('http://www.google.com') r.wait(2.0) r.type('/html/body/div[1]/div[3]/form/div[1]/div[1]/div[1]/div/div[2]/input', 'lubrificador para sexo anal[enter]') r.wait(2.0) r.snap('page', 'rpa_search.png') r.wait(2.0) r.close()
usep_lr=model_usep.fit(y,z) usep_pred_arr = usep_lr.predict(np.array([[demand_predicted]])) usep_pred =usep_pred_arr[0][0] return demand_predicted,usep_pred print(get_period_nbr()) period_nbr=get_period_nbr() today = datetime.today() #os.chdir("D:") r.init() r.url('https://www.emcsg.com/marketdata/priceinformation') r.wait(2) print(r.read('//table[@class="ptable realtimePriceTable"]//tr[@class="current"]')) data_list=r.read('//table[@class="ptable realtimePriceTable"]//tr[@class="current"]').splitlines() data_list[0]=today.strftime('%d/%m/%Y') data_list[1]=get_period_nbr() data_list[2]=float(data_list[2]) data_list[3]=float(data_list[3]) data_list[4]=float(data_list[4]) data_list[6]=float(data_list[6]) if data_list[6]==0: data_list.append(0) else: data_list.append(1) data_list=[data_list] df_current = DataFrame (data_list,columns=['Date','Period','Demand','TCL','USEP','EHEUR','LCP','Regulation','Primary','Secondary','Contingency','DR']) df_current = df_current[['Date','Period','USEP','LCP','Demand','TCL','DR']]
def extract_stay_info_as_data( ): #Generates URL/text in dict instead, shorten time for upload/download, more unified data = { "0": { "name": "", "description": "", "inventory": "", "price": "", "rating": "", "picurl": [None] * 10, "pictext": [None] * 10, "url": "" }, "1": { "name": "", "description": "", "inventory": "", "price": "", "rating": "", "picurl": [None] * 10, "pictext": [None] * 10, "url": "" }, "2": { "name": "", "description": "", "inventory": "", "price": "", "rating": "", "picurl": [None] * 10, "pictext": [None] * 10, "url": "" }, "3": { "name": "", "description": "", "inventory": "", "price": "", "rating": "", "picurl": [None] * 10, "pictext": [None] * 10, "url": "" }, "4": { "name": "", "description": "", "inventory": "", "price": "", "rating": "", "picurl": [None] * 10, "pictext": [None] * 10, "url": "" } } print('Extracting Top 5 Stay Picture Information (10 Image Max)..') url = [] url = get_stay_url() i = 0 k = 0 while (i < 5): data[str(i)]["url"] = url[i + k] r.url(url[i + k]) print(f'Extracting Text Data - Homestay {i+1}') if (r.exist( '//*[@data-plugin-in-point-id="TITLE_DEFAULT"]/div/div/section/div/div/h1' ) == True): data[str(i)]["name"] = r.read( '//*[@data-plugin-in-point-id="TITLE_DEFAULT"]/div/div/section/div/div/h1' ) data[str(i)]["description"] = r.read( '//*[@data-plugin-in-point-id="OVERVIEW_DEFAULT"]/div/div/div/section/div/div/div/div/div' ) data[str(i)]["description"] = data[str(i)]["description"].replace( "\xa0", " ") data[str(i)]["inventory"] = r.read( '//*[@data-plugin-in-point-id="OVERVIEW_DEFAULT"]/div/div/div/section/div/div/div/div/div[2]' ) data[str(i)]["price"] = r.read( '//*[@data-plugin-in-point-id="BOOK_IT_SIDEBAR"]/div/div[2]/div/ul[2]/li/span[2]' ) #Total Price if r.present( '//*[@data-plugin-in-point-id="REVIEWS_DEFAULT"]/div/div/section/div/div/div/h2/span[2]/span' ): data[str(i)]["rating"] = r.read( '//*[@data-plugin-in-point-id="REVIEWS_DEFAULT"]/div/div/section/div/div/div/h2/span[2]/span' ) else: data[str(i)]["rating"] = "No Reviews Yet" r.click('//*[@id="FMP-target"]') j = 0 while (1): j = j + 1 print(f'Extracting Picture Data - Homestay {i+1} Photo {j}') r.wait(0.4) #r.snap('//div[@data-testid="photo-viewer-slideshow-desktop"]/div/div/div/div/div/img',f"data/{i+1}/{j}.jpg") #fastest but not perfect if (r.exist( '//div[@data-testid="photo-viewer-slideshow-desktop"]/div/div/div/div/div/img/@src' ) == True): data[str(i)]["picurl"][j - 1] = r.read( '//div[@data-testid="photo-viewer-slideshow-desktop"]/div/div/div/div/div/img/@src' ) if (r.present( '//div[@data-testid="photo-viewer-slideshow-desktop"]/div/div/div/div[2]/div/span/div/span' ) == True): data[str(i)]["pictext"][j - 1] = r.read( '//div[@data-testid="photo-viewer-slideshow-desktop"]/div/div/div/div[2]/div/span/div/span' ) #r.download(dl_link,f'data/{i+1}/{j}.jpg') print(f'Homestay {i+1} Photo {j} extracted!') if (r.exist('//*[@aria-label="Next"]') == False or j >= 10): break r.click('//*[@aria-label="Next"]') else: i = i - 1 #Detects Whales (Airbnb Plus spoils the format alot) k = k + 1 #Compensating Constant k print("WHALE detected, adding one more loop..") i = i + 1 #r.click('/html/body/div[9]/div/div/div/section/div/div[1]/div/button') print('Done.') return data
import rpa import pyautogui rpa.init(visual_automation=False, chrome_browser=True) rpa.url('https://www.melhorcambio.com/dolar-hoje') rpa.wait(5.0) janela = pyautogui.getActiveWindow() janela.maximize() rpa.type('//*[@id="original"]', '10') pyautogui.sleep(2) dolar_comercial = rpa.read('//*[@id="comercial"]') pyautogui.sleep(2) print(dolar_comercial) janela.close()
searchbutton = searchbuttonid if not r.exist('//*[@id="'+account1box+'"]'): i+=1 continue #enter account number r.type('//*[@id="'+account1box+'"]', "[clear]") r.type('//*[@id="'+account1box+'"]', acc[0]) r.type('//*[@id="'+account2box+'"]', "[clear]") r.type('//*[@id="'+account2box+'"]', acc[1]) #click search r.click('//*[@id="'+searchbutton+'"]') while r.present('//*[@class="busy-load-container"'): r.wait(2) r.wait(2) #account exist? txt = r.read('body') if "No accounts were found matching your search criteria" in txt: runningLog(row[0] + ': Account does not exist') break #click last bill if r.present('Latest bill'): #Billing history has no this button, download link displayed already r.click('Latest bill') r.wait(1) while r.present('//*[@class="busy-load-container"'): r.wait(2) r.wait(2)
# open browser r.init(True) # go to amazon sign in page r.url( 'https://www.amazon.com/ap/signin?_encoding=UTF8&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%2Fgp%2Fyourstore%2Fhome%3Fie%3DUTF8%26action%3Dsign-out%26path%3D%252Fgp%252Fyourstore%252Fhome%26ref_%3Dnav_youraccount_signout%26signIn%3D1%26useRedirectOnSuccess%3D1' ) # sign into amazon account r.type('text', '******[enter]') # enter amazon username here r.type('text', '*******[enter]') # enter password here # click to go to delivery window page r.click('Cart') r.click('Checkout Whole Foods Market Cart') r.click('continue') r.click('continue') r.wait(20) # save screenshot file r.snap('page', 'results.png') # use open to extract delivery availability msg filename = 'results.png' img = cv2.imread(filename) imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # convert to gray filename_gray = filename + '_box.jpg' cv2.imwrite(filename_gray, imgray) r.close() _, thresh = cv2.threshold(imgray, 180, 255, cv2.THRESH_BINARY_INV) kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5)) #rectangle shape dilated = cv2.dilate(thresh, kernel, iterations=2)
import rpa as r import pyautogui as ui r.init() r.url('http://www.google.com') r.url() janela = ui.getActiveWindow() janela.maximize() r.wait(2.0) r.type('/html/body/div[1]/div[3]/form/div[2]/div[1]/div[1]/div/div[2]/input', 'RPA[enter]') r.wait(0.5) r.snap('page', 'rpa_page.png') r.wait(2.0) r.close()
if __name__ == '__main__': env = 'staging' user = '******' pwd = '_N0SePuede0909' cred = get_credential_data(env) #print(cred) r.init() ## LOGIN admin_url = cred['base_url'] + cred['roles']['admin']['url'] username = cred['roles']['admin']['username'] password = cred['roles']['admin']['password'] login_to_admin(admin_url, username, password) ## CHANGE PASSWORD r.wait(2) success = change_password(user, pwd) print(success) ## LOGOUT FROM ADMIN logout_from_admin() ## LOGIN TO THE APP url = cred['base_url'] + 'accounts/login/' app_login(user, pwd, url) r.wait(30) r.close()
import rpa as r r.init(visual_automation=True, chrome_browser=False) r.keyboard('[cmd][space]') r.keyboard('safari[enter]') r.keyboard('[cmd]t') r.keyboard('joker[enter]') r.wait(2.5) r.snap('page.png', 'results.png') r.close()
import rpa as r r.init(visual_automation=True) r.url("https://www.4devs.com.br/gerador_de_pessoas") def click(times, element): for i in range(1, times + 1): r.click(element) r.hover('images/arrow-down.png') click(6, 'images/arrow-down.png') r.hover('images/select-number-of-persons.png') click(1, 'images/select-number-of-persons.png') r.type('6. Gerar quantas pessoas? (Máx.: 30)', '0') r.hover('images/generate-person.png') click(1, 'images/generate-person.png') r.hover('images/download-button.png') click(1, 'images/download-button.png') r.wait(5) r.close()
def snap(): r.wait(20) r.snap('page','results.png')
err=False while tempNum==atmNumber: reps+=1 if reps>5: break # checkWhatsError = r.read('//*[@id="fallback_block"]/div/a') # print('Error '+ checkWhatsError) # if checkWhatsError == 'Descargar': # print('Error found') # err=True # break tempNum = r.read('//*[@id="main_block"]/div[1]/h1/p/span') print(atmNumber + " ==? " + tempNum) if n ==0: break r.wait(0.2) #if err: # continue if reps >5: print('Atasco capturar este error') numErroneosURL.append(list[i]) numErroneos.append(atmNumber) cantidadNoEnviados +=1 continue atmNumber = tempNum r.click('//*[@id="action-button"]') r.wait(0.3) s = r.read(580, 350,850,400) print(s) if s == "Phone number shared via url is invalid.": print("Numero erroneo")
#output.write(req.content) #populates the source into the file #output.close() #closes and saves the file #---- at this point the file should be ready to be read #if neither the download or the requests.get work - using rpa.click() to click on the css object to download works but takes extra steps # load and prepare all data to string with pandas df = pd.read_excel('challenge.xlsx') df['Phone Number'] = df['Phone Number'].astype(str) # timer starts after running this step r.click('//*[text()="Start"]') # iterate and populate each text box on the page for i in range(len(df.axes[0])): r.type('//*[@ng-reflect-name="labelFirstName"]', df['First Name'][i]) r.type('//*[@ng-reflect-name="labelLastName"]', df['Last Name '][i]) r.type('//*[@ng-reflect-name="labelCompanyName"]', df['Company Name'][i]) r.type('//*[@ng-reflect-name="labelRole"]', df['Role in Company'][i]) r.type('//*[@ng-reflect-name="labelAddress"]', df['Address'][i]) r.type('//*[@ng-reflect-name="labelEmail"]', df['Email'][i]) r.type('//*[@ng-reflect-name="labelPhone"]', df['Phone Number'][i]) r.click('//*[@value="Submit"]') # page as identifier means the webpage r.snap('page', 'score.png') r.wait(10) r.close() #---End of program | https://github.com/eabdiel
def sigaaRPA(self): r.init() r.timeout(30) while(self.state > 0): if self.terminateBot: r.close() break elif self.state == 1: # use url('your_url') to go to web page, url() returns current URL r.url('https://sigaa.upb.edu.co/ssomanager/c/SSB') self.state = self.state + 1 elif self.state == 2: # use type() to use the keyboard to write something if r.exist(X.username) & r.present(X.username): r.type(X.username, '000290164') r.type(X.password, 'Tandres1997_') self.state = self.state + 1 else: print("Couldn\'t find Username and Password Components") self.state = 1 elif self.state == 3: # use click() to click on an UI element or x, y location self.state = click(X.login, self.state) elif self.state == 4: ## hace click en Estudiantes self.state = click(X.estudiantes, self.state) elif self.state == 5: ## Hace click en Seguimiento a la formación self.state = click(X.seguimieto, self.state) elif self.state == 6: ## hace click en Calificaciones parciales self.state = click(X.calif, self.state) elif self.state == 7: ## Selecciona el semestre del cual quiere mirar las notas r.select(X.semester, self.semester) self.state = self.state + 1 elif self.state == 8: ## se hace click en enviar r.click(X.enviar) self.state = self.state + 1 elif self.state == 9: tablexpath = '' r.wait(2) numCursos = r.count('//*[@class="datadisplaytable"][2]/tbody/tr/td/a') for i in range(2,numCursos+2): tablexpath = '//*[@class="datadisplaytable"][2]/tbody/tr['+ str(i) +']/td/a' if r.exist(tablexpath): r.click(tablexpath) r.wait(1) pagetitle = r.read('//div[@id="pagetitle"]') if pagetitle == 'Detalle de Calificación de Componente': materia = r.read('//*[@class="datadisplaytable"][1]/tbody/tr[5]/td[2]') print(materia) r.snap('page', './notas/s'+self.semester+'/'+ materia +'.png') # r.table('//table[@class="datadisplaytable"][2]', './csv/table'+str(i-1)+'.csv') r.dom('history.back()') # use wait() to wait for a number of seconds # default wait() is 5 seconds r.wait(5) self.terminateBot = True elif self.state == 10: r.dom('history.back()')
# use type() to enter text into an UI element or x, y location # '[enter]' = enter key, '[clear]' = clear field r.type('ybar-sbq', 'github') # use read() to fetch and return text from UI element search_text = r.read('ybar-sbq') print(search_text) # use click() to click on an UI element or x, y location # rclick() = right-click, dclick() = double-click r.click('ybar-search') # use wait() to wait for a number of seconds # default wait() is 5 seconds r.wait(6.6) # use snap() to save screenshot of page or UI element # page = web page, page.png = computer screen r.snap('page', 'results.png') r.snap('logo', 'logo.png') # another example of interacting with a web page # include http:// or https:// in URL parameter r.url('https://duckduckgo.com') r.type('search_form_input_homepage', 'The search engine that doesn\'t track you.') r.snap('page', 'duckduckgo.png') r.wait(4.4) # use close() to close TagUI process and web browser # if you forget to close, just close() next time
def extract_stay_info_as_data( ): #Generates URL/text in dict instead, shorten time for upload/download, more unified data = { "0": { "name": "", "description": "", "inventory": "", "price": "", "rating": "", "picurl": [None] * 10, "pictext": [None] * 10, "url": "", "coordinates": "" }, "1": { "name": "", "description": "", "inventory": "", "price": "", "rating": "", "picurl": [None] * 10, "pictext": [None] * 10, "url": "", "coordinates": "" }, "2": { "name": "", "description": "", "inventory": "", "price": "", "rating": "", "picurl": [None] * 10, "pictext": [None] * 10, "url": "", "coordinates": "" }, "3": { "name": "", "description": "", "inventory": "", "price": "", "rating": "", "picurl": [None] * 10, "pictext": [None] * 10, "url": "", "coordinates": "" }, "4": { "name": "", "description": "", "inventory": "", "price": "", "rating": "", "picurl": [None] * 10, "pictext": [None] * 10, "url": "", "coordinates": "" } } print('Extracting Top 5 Stay Picture Information (10 Image Max)..') url = [] url = get_stay_url() i = 0 k = 0 while (i < 5): data[str(i)]["url"] = url[i + k] r.url(url[i + k]) print(f'Extracting Text Data - Homestay {i+1}') if (r.exist('//*[@itemprop="name"]/span/h1/span') == True): data[str(i)]["coordinates"] = r.read( '//*[@data-veloute="map/GoogleMap"]/div/div/div/div[2]/a/@href' ).split("=", 1)[1].split("&", 1)[0] data[str(i)]["name"] = r.read('//*[@itemprop="name"]/span/h1/span') data[str(i)]["description"] = r.read( '//*[@href="#neighborhood"]/div') #data[str(i)]["description"]=data[str(i)]["description"].replace("\xa0"," ") data[str(i)]["inventory"] = r.read( '//*[@id="room"]/div[2]/div/div[2]/div/div/div[3]/div/div/div[1]/div/div/div[1]/div' ) + " " + r.read( '//*[@id="room"]/div[2]/div/div[2]/div/div/div[3]/div/div/div[1]/div/div/div[2]/div' ) + " " + r.read( '//*[@id="room"]/div[2]/div/div[2]/div/div/div[3]/div/div/div[1]/div/div/div[3]/div' ) + " " + r.read( '//*[@id="room"]/div[2]/div/div[2]/div/div/div[3]/div/div/div[1]/div/div/div[4]/div' ) if (r.present('//*[@id="book_it_form"]/div[4]/div[2]') == True): data[str(i)]["price"] = r.read( '//*[@id="book_it_form"]/div[4]/div[2]').split("Total", 1)[1] else: data[str(i)]["price"] = r.read( '//*[@id="book_it_form"]/div[2]').split("Total", 1)[1] #Total Price if r.present('//*[@data-heading-focus="review header"]/div'): data[str(i)]["rating"] = r.read( '//*[@data-heading-focus="review header"]/div/div/@aria-label' ) + " (" + r.read( '//*[@data-heading-focus="review header"]/div/span') + ")" else: data[str(i)]["rating"] = "No Reviews Yet" r.click('//*[@data-veloute="hero-view-photos-button"]') j = 0 while (1): j = j + 1 print(f'Extracting Picture Data - Homestay {i+1} Photo {j}') r.wait(0.4) #r.snap('//div[@data-testid="photo-viewer-slideshow-desktop"]/div/div/div/div/div/img',f"data/{i+1}/{j}.jpg") #fastest but not perfect if (r.exist('//img[@data-veloute="slideshow-image"]/@src') == True): data[str(i)]["picurl"][j - 1] = r.read( '//img[@data-veloute="slideshow-image"]/@src') if (r.present( '//*[@data-veloute="slideshow-modal"]/div/div/div[2]/div[2]/div[2]/div[2]/div' ) == True): data[str(i)]["pictext"][j - 1] = r.read( '//*[@data-veloute="slideshow-modal"]/div/div/div[2]/div[2]/div[2]/div[2]/div' ) #r.download(dl_link,f'data/{i+1}/{j}.jpg') print(f'Homestay {i+1} Photo {j} extracted!') if (r.exist('//button[@aria-label="Next"]') == False or j >= 10): break r.click('//button[@aria-label="Next"]') else: i = i - 1 #Detects Whales (Airbnb Plus spoils the format alot) k = k + 1 #Compensating Constant k print("WHALE detected, adding one more loop..") i = i + 1 #r.click('/html/body/div[9]/div/div/div/section/div/div[1]/div/button') print('Done.') return data