def monthyearnavigate(monthyear): compare = r.read( '//*[@aria-roledescription="datepicker"]/div/div[1]/div[2]/div/div/div') while(monthyear != compare): r.click('//*[contains(@aria-label,"Next")]') compare = r.read( '//*[@aria-roledescription="datepicker"]/div/div[1]/div[2]/div/div/div')
def click(xpath, s): if r.exist(xpath) & r.present(xpath): r.click(xpath) return s + 1 else: print('Couldn\'t find' + xpath + ' component') return s
def initialize(): print('Initializing...') r.init() r.url(URL) if r.exist('//*/button[@type="submit"]') == True: r.click('//*/button[@type="submit"]') # Anti RPA by AirBnB print('Done.')
def enter_country_city(city): print(f'Entering City Information...{city}') r.click('//*[@aria-label="Search"]') r.type('//*[@placeholder="Add city, landmark, or address"]', city) #r.type('//*[@id="Koan-via-SearchHeader__input"]', city) #r.click('//*[@id="Koan-via-SearchHeader__option-0"]') 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 check(): a = r.init(visual_automation=True, chrome_browser=False) print(a) b = r.run(r'C:\Users\20945\AppData\Local\UB_Store\Store.exe') print(b) r.click(0, 0) r.rclick(0.0) pass
def initialize(): print('Initializing...') r.init() r.timeout(15) #set timeout to wait longer r.url(URL) while r.exist('//*/button[@type="submit"]') == False: r.url(URL) print("Wrong page detected, retrying..") r.click('//*/button[@type="submit"]') # Anti RPA by AirBnB print('Done.')
def dollar_cannadian(): r.init() r.url('https://www.melhorcambio.com/dolar-hoje') sleep(4) r.click('//*[@id="dock"]/ul/li[2]/a') sleep(4) dolar_c = r.read('//*[@id="comercial"]') sleep(2) print(f'{dolar_c} | {datetime.today()}') r.close() return dolar_c
def enter_personnel(adult, child, infant): print('Entering Personnel Information..') r.click('//*[@id="filter-menu-chip-group"]/div[3]/*') for _i in range(adult): r.click('//*[@id="filterItem-stepper-adults-0"]/button[2]') for _i in range(child): r.click('//*[@id="filterItem-stepper-children-0"]/button[2]') for _i in range(infant): r.click('//*[@id="filterItem-stepper-infants-0"]/button[2]') r.click('//*[@id="filter-panel-save-button"]') print('Done.')
def do_web_auto(search_data): r.init() r.url('https://www.google.com') r.click('.gLFyf.gsfi') r.type('.gLFyf.gsfi', f'{search_data}[enter]') #r.type("//*[@name='q']', 'decentralization[enter]") #print(r.read('result-stats')) r.snap('page', 'results.png') res = r.read('result-stats') r.close() return res
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 enter_dates(checkin, checkout): checkinmonthyear = monthyearconversion(checkin) #r.click('//*[@id="menuItemButton-date_picker"]/button') r.click('//*[@id="filter-menu-chip-group"]/div[2]/*') monthyearnavigate(checkinmonthyear) r.click(f'//*[contains(@aria-label,"{checkin}")]') monthyearnavigate(monthyearconversion(checkout)) r.click(f'//*[contains(@aria-label,"{checkout}")]') r.click('//*[@id="filter-panel-save-button"]')
def enter_personnel(adult, child, infant): r.click('//*[@role="search"]/div/div/div[5]/div/button') print('Entering Personnel Information..') #r.click('//*[@id="filter-menu-chip-group"]/div[3]/*') for _i in range(adult): r.click('//*[@aria-describedby="subtitle-label-stepper-adults"][2]') for _i in range(child): r.click('//*[@aria-describedby="subtitle-label-stepper-children"][2]') for _i in range(infant): r.click('//*[@aria-describedby="subtitle-label-stepper-infants"][2]') #r.click('//*[@id="filter-panel-save-button"]') print('Done.')
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 start_challenge(data_frame, labels_list): r.click('/html/body/app-root/div[2]/app-rpa1/div/div[1]/div[6]/button') count_round = 1 for row in data_frame.itertuples(): if count_round == 11: break else: for label in range(0, 7): row_converted_to_string = str(row[label + 1]) if label == 6: r.type(f'//*[@ng-reflect-name="{labels_list[label]}"]', row_converted_to_string[:-2]) else: r.type(f'//*[@ng-reflect-name="{labels_list[label]}"]', row_converted_to_string) r.click( '/html/body/app-root/div[2]/app-rpa1/div/div[2]/form/input') count_round += 1
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 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 logout(): r.init(visual_automation=True, chrome_browser=False) r.run('C:\Servyou\EPPortal_DS3.0\EPEvenue_SH.exe') if r.exist("a.png"): r.click("a.png") r.click("b.png") r.click("c.png") # 13s pass
def enter_dates(checkin, checkout): r.click('//*[@role="search"]/div/div/div[3]/div/button') print(f'Entering Check in and Check out Dates..{checkin} to {checkout}') checkinmonthyear = monthyearconversion(checkin) # r.click('//*[@id="menuItemButton-date_picker"]/button') # r.click('//*[@id="filter-menu-chip-group"]/div[2]/*') monthyearnavigate(checkinmonthyear) r.click(f'//*[contains(@aria-label,"{checkin}")]') monthyearnavigate(monthyearconversion(checkout)) r.click(f'//*[contains(@aria-label,"{checkout}")]') print('Done.')
def carrefuorRegisterRpa(cnpj, customerFirstName, customerLastName, displayName, companyName, registrationMunicipal, registrationState, category, platform, loginEmail, phone): url = 'https://www.carrefour.com.br/marketplace/inscreva-se' r.init() r.url(url) time.sleep(10) r.click('//*[@id="onetrust-accept-btn-handler"]') time.sleep(3) r.click('//*[@id="00N6g00000RpFD9"]') r.click('//*[@id="00N6g00000RpFD9"]')
def login_to_admin(admin_url, username, password): r.url(admin_url) element = '//input[@id="id_username"]' if r.exist(element): print('Login') r.click(element) r.type(element, username) element = '//input[@id="id_password"]' r.click(element) r.type(element, password) #print(element, password) element = '//input[@type="submit"]' r.click(element) else: print('Already logged in')
r.init() # use url('your_url') to go to web page, url() returns current URL r.url('https://ca.yahoo.com') # 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.init() # use url('your_url') to go to web page, url() returns current URL r.url('https://ca.yahoo.com') # use type() to enter text into an UI element or x, y location # '[enter]' = enter key, '[clear]' = clear field r.type('search-input', 'github') # use read() to fetch and return text from UI element search_text = r.read('search-input') print(search_text) # use click() to click on an UI element or x, y location # rclick() = right-click, dclick() = double-click r.click('search-button') # 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.')
wb = openpyxl.Workbook() sheet = wb.active sheet.cell(row=1, column=1).value = 'Name' sheet.cell(row=1, column=2).value = 'Price' r.init() # get URL of old groceries order to re-add all items to cart # r.url(r.ask('Paste the URL of Purchase History Link and login to Nintendo')) # r.url('https://ec.nintendo.com/my/#/transactions/1') r.url('https://ec.nintendo.com/my/#/') t.sleep(7) # click on purchase history if logged in r.click( '/html/body/div[1]/div[2]/section/div[1]/section[2]/section/ul/li[3]/a/div[1]' ) t.sleep(5) r.timeout(300) # set a maximum 5-minute timeout for user to login # t.sleep(300) # use exist() function with XPath to check if logged in if not r.exist( '/html/body/div[1]/div[2]/section/div[1]/section[2]/div/div/section[1]/div[2]/div/div[1]/div[2]' ): r.dom('alert("Purchase History Page not detected after 5 minutes. Bye!")') # then click on last item arrow r.click( '/html/body/div[1]/div[2]/section/div[1]/section[2]/div/div/ni-pager/section/div/button[9]'
def close_cookie_popup(): if r.present("//button[@class='optanon-allow-all accept-cookies-button']" ) == True: r.click("//button[@class='optanon-allow-all accept-cookies-button']")
def click_search(): r.click('//button[@type="submit"]')
def select_stay(): print('Selecting "Stays"...') r.click('//*[@id="Koan-via-SearchHeader__input"]') r.click('//*[@id="Koan-via-SearchHeader__option-1"]') print('Done.')
def logout(): # GG CAPTCHA (abandoned ship) r.click('//header[@role="banner"]/div/div/div[3]/div/div/nav/ul/li[6]') r.click('//*[@id="headerNavUserMenu"]/li[8]/form/button')
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