def shot(cap, url, ads=None): webdriver = webdriver.Remote(hubUrl, desired_capabilities=cap, proxy=proxy) webdriver.set_window_size(1024, 800) webdriver.get(url) if ads: sizeJs = "elm=document.getElementById(\"%s\");\ elm.style.display=\"block\";elm.style.width=\"%s px\";\ elm.style.height=\"%s px\";elm.style.overflow=\"hidden\";" for ad in ads: elm = webdriver.find_element_by_id(ad["id"]) if ad["size"] != (elm.size["width"], elm.size["height"]): webdriver.execute_script(sizeJs % (ad["id"], ad["size"][0], ad["size"][1])) try: ads = webdriver.execute_script("return pozice;") except selenium.common.exceptions.WebDriverException: ads = [] for ad in ads: elm = webdriver.find_element_by_id(ad["id"]) ad["size"] = elm.size["width"], elm.size["height"] ad["location"] = elm.location["x"], elm.location["y"] for dId in debugIds: webdriver.execute_script(removeDebug % dId) _, filename = tempfile.mkstemp() webdriver.save_screenshot(filename) data = open(filename).read() os.remove(filename) return data, ads
def runFollowersFollow(self, webdriver, person, account, stopFlag): sleep(2) webdriver.get('https://www.%s.com/%s/followers/' % (str.lower(account.accountType), person)) sleep(1) follow_list = webdriver.find_elements_by_xpath(self.follow_list) maxVal = len(follow_list) followDoc = open("./bot_docs/masterList.txt", "a") for index in range(1, 10): try: followButton = webdriver.find_element_by_xpath( self.follow_list_item + str(index) + ']/div/div[3]/button') accountName = webdriver.find_element_by_xpath( self.follow_list_item + str(index) + ']/div/div[2]/div[1]/div/div/a') webdriver.execute_script( "return arguments[0].scrollIntoView();", followButton) sleep(random.uniform(0, 1)) # if(followButton.text=='Follow' and accountName.text not in clickedList.split(',')[0]): # followButton.click() # followDoc.write(accountName.text + ', ' + accountName.get_attribute("href") + datetime.today().strftime('%Y-%m-%d') + '\n') except: print("no follow button: " + self.follow_list_item + str(index) + ']/div/div[3]/button') followDoc.close()
def likes(): hashtag_list = open("hashtaglist.txt").readlines() tag = -1 goalLikes = int( input( '\033[0;33mHow many likes should we do in each hashtag?:\033[m ')) for hashtag in hashtag_list: currentLikes = 0 tag = tag + 1 print('\033[0;33mLiking the hashtag:\033[m ' + hashtag_list[tag]) webdriver.get('https://www.instagram.com/explore/tags/' + hashtag_list[tag] + '/') image_img = webdriver.find_element_by_xpath( '/html/body/div[1]/section/main/article/div[2]/div/div[1]/div[1]') sleep(1) image_img.click() sleep(1) try: while (currentLikes != goalLikes): sleep(3) image_like_svg = webdriver.find_element_by_css_selector( 'body > div._2dDPU.CkGkG > div.zZYga > div > article > div.eo2As > section.ltpMr.Slqrh > span.fr66n > button > div > span > svg' ) image_like_label = image_like_svg.get_attribute("aria-label") if image_like_label == "Like": image_like_svg.click() currentLikes += 1 print('Liked images: \033[0;33m{}\033[m'.format( currentLikes)) print("Looking for image...") sleep(randint(3, 7)) image_next = webdriver.find_element_by_class_name( 'coreSpriteRightPaginationArrow') image_next.click() elif image_like_label == "Unlike": print('\033[0;33mImage already liked.\033[m') image_next = webdriver.find_element_by_class_name( 'coreSpriteRightPaginationArrow') image_next.click() sleep(randint(1, 4)) else: sleep(5) image_next = webdriver.find_element_by_class_name( 'coreSpriteRightPaginationArrow') image_next.click() sleep(1) except: print( 'Oops, Instagram is having trouble in this tag, lets go to the next one. ' ) image_next = webdriver.find_element_by_class_name( 'coreSpriteRightPaginationArrow') image_next.click() continue print("\033[0;33mFinished liking hashtag:\033[m " + hashtag_list[tag]) sleep(1) print("\033[0;33mFinished liking all hashtags in the hashtag list.\033[m") goHome() sleep(2) menu()
def auto_login(webdriver, login_username, login_password): webdriver.get( 'https://www.instagram.com/accounts/login/?source=auth_switcher' ) # Access Instagram login page sleep(3) # Navigate login infor box username = webdriver.find_element_by_name('username') username.send_keys('') username.send_keys(login_username) password = webdriver.find_element_by_name('password') password.send_keys('') password.send_keys(login_password) # Click log-in button_login = webdriver.find_element_by_css_selector( '#react-root > section > main > div > article > div > div:nth-child(1) > div > form > div:nth-child(4) > button > div' ) button_login.click() sleep(3) # Skip pop-up dialog # Comment these lines out, if you don't get a pop up asking about notifications notnow = webdriver.find_element_by_css_selector( '#react-root > section > main > div > div > div > section > div > button' ) notnow.click() sleep(3) notnow2 = webdriver.find_element_by_css_selector( 'body > div.RnEpo.Yx5HN > div > div > div > div.mt3GC > button.aOOlW.HoLwm' ) notnow2.click() sleep(3)
def hose_stock_list(): global webdriver chrome_driver_path = 'D:\python\selenium\driver\chromedriver.exe' chrome_options = Options() #chrome_options.page_load_strategy #chrome_options.add_argument('--headless') chrome_options.add_argument( '--user-data-dir=C:\\Users\\hung-pro7\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Default' ) webdriver = webdriver.Chrome(executable_path=chrome_driver_path, options=chrome_options) url = 'https://trade-hcm.vndirect.com.vn/chung-khoan/hose' webdriver.get(url) webdriver.find_element_by_xpath('//*[@id="menuWrp"]/div/a[2]').click() time.sleep(2) webdriver.find_element_by_xpath( '//*[@id="login-popup"]/form/div[1]/div/input').send_keys( "tuanhungstar") webdriver.find_element_by_xpath( '//*[@id="login-popup"]/form/div[2]/div/input').send_keys( "Khanhha-1") webdriver.find_element_by_xpath( '//*[@id="login-popup"]/form/button').click() time.sleep(2) webdriver.find_element_by_xpath( '//*[@id="nav"]/ul[1]/li[2]/a/span').click() time.sleep(2) HOSE_table = webdriver.find_elements_by_class_name('txt-gia-tran') HOSE_ticker = [] for row in HOSE_table: text = row.get_attribute('id').replace('ceil', '') HOSE_ticker.append(text) return HOSE_ticker
def login(server_url, webdriver): webdriver.get(server_url) # Click login link, switch to persona window webdriver.find_element_by_id('login').click() webdriver.switch_to_window('__persona_dialog') # Enter email address and password email_address_input = WebDriverWait(webdriver, 5).until( EC.element_to_be_clickable((By.XPATH, '//*[@id="authentication_email"]'))) email_address_input.send_keys(config.PERSONA_USER) webdriver.find_element_by_xpath('//*[@id="authentication_form"]/p[4]/button[1]').click() password_input = WebDriverWait(webdriver, 10).until( EC.element_to_be_clickable((By.XPATH, '//*[@id="authentication_password"]'))) password_input.send_keys(config.PERSONA_PASS) # Submit login form and switch back to previous window webdriver.find_element_by_xpath('//*[@id="authentication_form"]/p[4]/button[3]').click() webdriver.switch_to_window('') # Wait until profile name is clickable WebDriverWait(webdriver, 10).until( EC.element_to_be_clickable((By.ID, 'profile')))
def getNimDoc(search_query, number): wait = WebDriverWait(webdriver, 2) webdriver.get(url) search = webdriver.find_element_by_id("searchInput") search.send_keys(search_query + Keys.RETURN) sleep(2) page = webdriver.page_source soup = BeautifulSoup(page, 'html.parser') filter1 = soup.find_all('div', class_='nine columns') filter2 = filter1[0] filter3 = filter2.find_all('div', class_='search_results') filter4 = filter3[0] filter5 = filter4.find_all('li') n = 1 for i in filter5: if n <= number: get_title = i.a.text get_url = i.find('a').get('href') print(n, "Title = ", get_title, '\n', "Url = ", get_url, '\n') print( "-------------------------------------------------------------------------------------------------" ) n += 1 else: break
def instagram_login(self): """ Handles login to instagram and returns the webdriver for use downstream """ webdriver = self.webdriver sleep(2) webdriver.get('https://www.instagram.com/accounts/login/?source=auth_switcher') sleep(3) try: allow_cookies = webdriver.find_element_by_css_selector('body > div.RnEpo.Yx5HN > div > div > div > div.mt3GC > button.aOOlW.bIiDR') allow_cookies.click() except: pass sleep(3) username = webdriver.find_element_by_name('username') username.send_keys(self.username) password = webdriver.find_element_by_name('password') password.send_keys(self.password) button_login = webdriver.find_element_by_xpath('//*[@id="loginForm"]/div/div[3]/button/div') button_login.click() sleep(3) return webdriver
def order_to_string(webdriver, order_number, domain): webdriver.get( f"https://{domain}/admin/orders.php?page=1&oID={order_number}&action=edit&ro=1#wysylka" ) # receiver info receiver_form_address_group = webdriver.find_element_by_xpath( "//*[@id='receiverForm']/div") rows_receive = receiver_form_address_group.find_elements_by_xpath( "./div[starts-with(@class,'row')]") contents = [] for row in rows_receive: try: contents.append( row.find_element_by_xpath("./div[@class='content']")) except: continue # shipment info shipment_form_adrress_group = webdriver.find_element_by_xpath( "//*[@id='shipmentForm']/div") rows_ship = shipment_form_adrress_group.find_elements_by_xpath( "./div[starts-with(@class,'row')]") for row in rows_ship: try: contents.append( row.find_element_by_xpath("./div[@class='content']")) except: continue final_list = [content.text for content in contents if (content.text != '')] final_list.insert(0, str(order_number)) sleep(3) return ' '.join(map(str, final_list)) # formatting this list into a string
def main(argv): target_name = '' tracking_file = '' try: opts, args = getopt.getopt(argv, "ht:f:", ["ttarget=", "ffilename="]) except getopt.GetoptError: print("whatsapp-watchdog.py -i <Target Name> -f <tracking file name>") sys.exit(2) for opt, arg in opts: if opt == "-h": print( "whatsapp-watchdog.py -i <Target Name> -f <tracking file name>" ) sys.exit() elif opt in ("-t", "ttarget"): target_name = arg elif opt in ("-f", "ffilename"): tracking_file = arg webdriver = launch_webdriver("Firefox") webdriver.get("https://web.whatsapp.com") scan_QR_code(webdriver) watch_target(webdriver, target_name, tracking_file)
def downloadGameResults(webdriver, partidos): print('Games to download: {}'.format(len(partidos))) cont = 1 total = len(partidos) # we loop through the gathered download links for partido in partidos: print('Downloading Game result {}/{} {}'.format(str(cont), str(total), partido.titulo)) try: cont += 1 webdriver.get(partido.link) time.sleep(2) # if not ('P.Pospuesto' in partido.titulo): download = webdriver.find_element_by_class_name( 's_pdf_download_link') partido.download_link = download.get_attribute('href') webdriver.get(download.get_attribute('href')) partido.downloaded = True except: #partido.download_link = '' partido.downloaded = False print('Encountered an issue downloading results for {}'.format( partido.titulo)) # traceback.print_exc() return partidos
def login_selenium(): '''initiates a chrome_driver window and logs into account''' chromedriver_path = ( '/Users/Beto/galvanize/Instagram-API-python/InstagramAPI/chromedriver') webdriver = webdriver.Chrome(executable_path=chromedriver_path) sleep(2) webdriver.get( 'https://www.instagram.com/accounts/login/?source=auth_switcher') username = webdriver.find_element_by_name('username') username.send_keys('sf_clout') password = webdriver.find_element_by_name('password') password.send_keys('20190101') sleep(10) button_login = webdriver.find_element_by_xpath( '//*[@id="react-root"]/section/main/div/article/div/div[1]/div/form/div[4]/button/div' ) button_login.click() sleep(5) notnow = webdriver.find_element_by_css_selector( 'body > div.RnEpo.Yx5HN > div > div > div.mt3GC > button.aOOlW.HoLwm') notnow.click()
def scrape(self): try: print( "scraping www.cnn.com , please wait as it might take a while :)" ) webdriver.get('https://edition.cnn.com/') element = WebDriverWait(webdriver, 10).until( EC.presence_of_element_located((By.CLASS_NAME, "cn__title "))) source = webdriver.page_source soup = BeautifulSoup(source, 'html.parser') article_links = [] for ul in soup.find_all('ul'): if ( ul.h2 and 'Top' in ul.h2.string ): #if the ul element has a h2 child, and Top is in the h2 string for li in ul.find_all('li'): article_links.append(li.find('a').get('href')) self.scrape_from_articles(article_links) except TimeoutException as exception: print('timed out, check internet connection and try again') finally: print('done') webdriver.close() return ''
def get_job_listing_urls(search_query, page_number, webdriver): url = BASE_URL.format(search_query, page_number) tries = 0 while True: # Get url contents webdriver.get(url) html = webdriver.page_source soup = bs4.BeautifulSoup(html, "html.parser") content_search_results = soup.find_all( attrs={"class": "card-title-link bold"}) # Create list of job listings from url contents job_listing_urls = [] for job_listing in content_search_results: url = job_listing.get('href') url = url.split('?')[0] job_listing_urls.append(url) # Returns list if succeeded, otherwise retries for x times and returns None if job_listing_urls: print("[0] Retrieved job listing URLs for query '{}' on page '{}'". format(search_query, page_number)) return job_listing_urls else: if tries < MAX_TRIES_JOB_LISTING_URLS: tries += 1 print( "[!] Could not retrieve job listing URLs for query '{}' on page '{}', trying again ({})" .format(search_query, page_number, tries)) else: return None
def instaLogin(): print("WELCOME TO InstaDownloader by KSHITIJ") print("Navigating to Instagram Login Page") webdriver.get( "https://www.instagram.com/accounts/login/?source=auth_switcher") sleep(2) username = webdriver.find_element_by_name("username") print("Entering Username") username.click() username.send_keys(InstaUsername) password = webdriver.find_element_by_name("password") print("Entering Password") password.click() password.send_keys(InstaPassword) sleep(2) loginButton = webdriver.find_element_by_css_selector( "#react-root > section > main > div > article > div > div:nth-child(1) > div > form > div:nth-child(4) > button > div" ) sleep(1) loginButton.click() print("Logging in . . . ") sleep(2) if (len(webdriver.find_elements_by_class_name('eiCW-')) > 0): print("Incorrect Username or Password") exit()
def get_last_post(webdriver, account): webdriver.get(('https://www.instagram.com/{}/').format(account)) sleep(5) post_xpath = '//*[@id="react-root"]/section/main/div/div[3]/article/div/div/div/div/a' a = webdriver.find_element_by_xpath(post_xpath) url = a.get_attribute('href') print(url)
def login(webdriver): # Open the instagram login page webdriver.get( 'https://www.instagram.com/accounts/login/?source=auth_switcher') # sleep for 3 seconds to prevent issues with the server time.sleep(3) # Find username and password fields and set their input using our constants username = webdriver.find_element_by_name('username') username.send_keys('*****@*****.**') password = webdriver.find_element_by_name('password') password.send_keys('Aida72584') # Get the login button try: button_login = webdriver.find_element_by_xpath( '//*[@id="react-root"]/section/main/div/article/div/div[1]/div/form/div[4]/button' ) except: button_login = webdriver.find_element_by_xpath( '//*[@id="react-root"]/section/main/div/article/div/div[1]/div/form/div[6]/button/div' ) # sleep again time.sleep(2) # click login button_login.click() time.sleep(3) # In case you get a popup after logging in, press not now. # If not, then just return try: notnow = webdriver.find_element_by_css_selector( 'body > div.RnEpo.Yx5HN > div > div > div.mt3GC > button.aOOlW.HoLwm' ) notnow.click() except: return
def register(self, webdriver): webdriver.get('https://passport.yandex.ru/registration/mail') # may include verification of a phone number or email try: wait_for_page_load = WebDriverWait(webdriver, 4).until( EC.url_contains("registration/mail")) except selenium.common.exceptions.TimeoutException: raise errors.BadIpRequestException('Try to change proxy or wait') webdriver.find_element_by_xpath('//*[@id="firstname"]').send_keys( self.firstname) webdriver.find_element_by_xpath('//*[@id="lastname"]').send_keys( self.lastname) webdriver.find_element_by_xpath('//*[@id="login"]').send_keys( self.login) webdriver.find_element_by_xpath('//*[@id="password"]').send_keys( self.pswd) webdriver.find_element_by_xpath( '//*[@id="password_confirm"]').send_keys(self.pswd) webdriver.find_element_by_xpath( '//*[@id="root"]/div/div[2]/div/main/div/div/div/form/div[3]/div/div[2]/div/span' ).click() wait_for_element = WebDriverWait(webdriver, TIMEOUT).until( EC.element_to_be_clickable((By.XPATH, '//*[@id="hint_answer"]'))) webdriver.find_element_by_xpath('//*[@id="hint_answer"]').send_keys( 'da')
def main(): items = [] #Log in webdriver.get(MAIN_PAGE_URL) webdriver.find_element_by_id( 'ctl00_ContentPlaceHolder1_Username').send_keys( credentials['username']) webdriver.find_element_by_id( 'ctl00_ContentPlaceHolder1_Password').send_keys( credentials['password']) webdriver.find_element_by_name('ctl00$ContentPlaceHolder1$ctl04').click() #Set items to show = 100 webdriver.find_element_by_xpath( "//select[@name='ctl00$ContentPlaceHolder1$GridView1$ctl13$ctl11']/option[text()='100']" ).click() #Getting number of pages page_number = len( webdriver.find_elements_by_xpath( "//tr[@class='grid-pager']//table//tr/td[not(@class)]")) page_href_script = "__doPostBack('ctl00$ContentPlaceHolder1$GridView1','Page$%s')" #Extracting each page on the website for i in range(page_number): i += 1 if i != 1: webdriver.execute_script(page_href_script % i) # Wait for redirecting time.sleep(10) items += extract() #Insert into database all extracted items (rigs) insert_into_database(items)
def load_stockweb(stock_sn, datepath): nowget = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) #stock_sn="3231" #weblink = "http://traderoom.cnyes.com/tse/quote2FB.aspx?code="+stock_sn weblink = "https://stock.pchome.com.tw/stock/sto0/ock3/sid" + stock_sn + ".html" #r = requests.get(weblink,timeout=10) #r.encoding = "utf-8" #soup = BeautifulSoup(r.text, "lxml") webdriver.implicitly_wait(10) webdriver.get(weblink) print(webdriver.title) soup = BeautifulSoup(webdriver.page_source, "lxml") #fp = open("index.html", "w", encoding="utf8") #fp.write(soup.prettify()) #print("寫入檔案index.html...") #fp.close() #webdriver.quit() os.chdir("\\py3_prj\\pyweb\\stock_data\\" + datepath) sfilename = "stock" + stock_sn + "d" + nowget[0:10] + ".html" fp = open(sfilename, "w", encoding="utf8") fp.write(soup.prettify()) #print(nowget[0:10]) print("寫入檔案" + sfilename) fp.close()
def get_page_for_url(webdriver, url): while True: try: webdriver.get(url) break except: pass
def link_to_reset_pswd(self, webdriver): self.restore_link = None webdriver.get('https://mail.yandex.ru/lite') while self.restore_link == None: elements = webdriver.find_elements_by_class_name( 'b-messages__message__left') for i in range(len(elements)): time.sleep(2) try: element = elements[i].text if len( re.findall( 'https://accounts.epicgames.com/resetPassword\?code=(\w{32})', element)) != 0: self.restore_link = \ re.findall('https://accounts.epicgames.com/resetPassword\?code=(\w{32})', element)[0] except: pass else: time.sleep(REFRESH_SEC) webdriver.refresh() time.sleep(REFRESH_SEC) webdriver.refresh() print(self.restore_link) return 'https://accounts.epicgames.com/resetPassword\?code=' + self.restore_link
def get_soup(webdriver, base, link): webdriver.get(base + link) # url = urllib.request.urlopen(base + link) innerHTML = webdriver.page_source # soup = bs4.BeautifulSoup(url.read(), "html.parser") soup = BeautifulSoup(innerHTML, "html.parser") return soup
def scrape_page(webdriver, links, username): '''This function will go to all links provided and scrape each picture for the number of likes and the caption. If the link is a video no information is recorded. The function will only save the caption if the title is the identified user Parameters: the active webdriver, a set of picture links, the username of the page your are scraping Returns: a list of lists with the number of likes and caption ''' picture_info = [] for link in links: # Open new tab webdriver.execute_script("window.open('');") time.sleep(3) # Switch to the new window webdriver.switch_to.window(webdriver.window_handles[1]) webdriver.get(link) time.sleep(5) try: likes_list = webdriver.find_elements_by_class_name('zV_Nj') if len(likes_list) != 0: #If the length is 0, then it is a video if len(likes_list) == 1: #No common friends liked the photo num_likes = webdriver.find_elements_by_class_name('Nm9Fw')[0].text.split(' ')[0] else: num_likes = int(likes_list[1].text.split(' ')[0]) + 1 try: title = webdriver.find_element_by_class_name('_6lAjh').text if title == username: caption_list = webdriver.find_elements_by_xpath("//div[@class='C4VMK']//span") '''This code works but not active since I did not use the information num_of_comments = len(caption_list)''' caption = caption_list[0].text else: caption = None #if the user was not the title except: caption = None #photo does not have a caption or any comments picture_info.append([num_likes, caption]) except: pass webdriver.close() # Switch focus back to main tab webdriver.switch_to.window(webdriver.window_handles[0]) time.sleep(5) return picture_info
def goToProfile(profile): print("Navigating into " + InstaAccount) webdriver.get("https://www.instagram.com/" + InstaAccount + "/") if (len(webdriver.find_elements_by_class_name('error-container')) > 0): print("Account Doesnt Exists") exit() else: print(InstaAccount + " is opened")
def like(link): webdriver.switch_to.window(webdriver.window_handles[0]) webdriver.get(link) sleep(2) like = webdriver.find_element_by_class_name('fr66n') print(like) like.click() sleep(2)
def login(webdriver): webdriver.get(url) webdriver.implicitly_wait(10) webdriver.switch_to.frame(webdriver.find_element_by_tag_name('iframe')) webdriver.find_element_by_id('username').send_keys(USERNAME) webdriver.find_element_by_id('password').send_keys(PASSWORD) webdriver.find_element_by_xpath("//input[@type='image']").click() webdriver.implicitly_wait(5)
def getPageSource(webdriver,url): # opens url webdriver.get(url) time.sleep(3) # wait for 3 seconds for page to load try: return webdriver.page_source except: print "\nHTML get page source error!"
def open_browser_page(website_purpose, path, page_name): ensure_website_running(website_purpose) with require_current_context_being(BrowserPageContext(page_name)): with require_io_loop_executor(): webdriver = require_webdriver() webdriver.get(get_url(website_purpose, path)) assert_current_page(page_name) yield
def insta(): import selenium from selenium import webdriver from selenium.webdriver.common.keys import Keys USERNAME = str(input("Enetr your user name:")) PASSWORD = str(input("Enter Your Password:")) chromedriver_path = 'C:/chromedriver.exe' webdriver = webdriver.Chrome(executable_path=chromedriver_path) webdriver.get( 'https://www.instagram.com/accounts/login/?source=auth_switcher') sleep(5) username = webdriver.find_element_by_name('username') username.send_keys(USERNAME) password = webdriver.find_element_by_name('password') password.send_keys(PASSWORD) button_login = webdriver.find_element_by_css_selector( '#react-root > section > main > div > article > div > div:nth-child(1) > div > form > div:nth-child(4) > button > div' ) button_login.click() sleep(6) not_now = webdriver.find_element_by_css_selector( '#react-root > section > main > div > div > div > div > button') not_now.click() sleep(6) notnow = webdriver.find_element_by_css_selector( 'body > div.RnEpo.Yx5HN > div > div > div > div.mt3GC > button.aOOlW.HoLwm' ) notnow.click() def inbox(): button_inbox = webdriver.find_element_by_css_selector( '#react-root > section > nav > div._8MQSO.Cx7Bp > div > div > div.ctQZg > div > div:nth-child(2) > a > svg' ) button_inbox.click() sleep(10) button_home = webdriver.find_element_by_css_selector( '#react-root > section > div > div._lz6s.Hz2lF > div > div.ctQZg > div > div:nth-child(1) > div > a > svg' ) button_home.click() inbox() sleep(10) def activity(): button_activity = webdriver.find_element_by_css_selector( '#react-root > section > nav > div._8MQSO.Cx7Bp > div > div > div.ctQZg > div > div:nth-child(4) > a > svg' ) button_activity.click() sleep(2) activity() webdriver.quit()
def setup(): webdriver.get( 'https://randomwordgenerator.com/would-you-rather-question.php') sleep(1) qinput = webdriver.find_element_by_tag_name("input") qinput.clear() qinput.send_keys("50") return qinput
def Search(): speak("Which Song?") # SELECTION OF SONG SearchText = takeCommand().lower() speak("let's go to youtube") webdriver.get("https://www.youtube.com/results?search_query=" + SearchText) sleep(2) # x = webdriver.find_element_by_class_name("style-scope ytd-video-renderer").click() x = webdriver.find_element_by_xpath("/html/body/ytd-app/div/ytd-page-manager/ytd-search/div[1]/ytd-two-column-search-results-renderer/div/ytd-section-list-renderer/div[2]/ytd-item-section-renderer/div[3]/ytd-video-renderer[1]/div[1]/div/div[1]/div/h3/a/yt-formatted-string").click() sleep(2)
def take_screenshot(url): try: webdriver = selenium.webdriver.PhantomJS('vendor/phantomjs/bin/phantomjs') webdriver.get(url) webdriver.set_window_size(1280,800) imagedata = webdriver.get_screenshot_as_base64() webdriver.close() webdriver.quit() except Exception, e: raise
def urlLoad(webdriver, url): """ Loads the page using the webdriver with a given URL webdriver: Selenium's webdriver object url: string return: it updates the webdriver and prints confirmation. """ webdriver.get(url) print "Page loaded successfuly."
def _screenshot(self, webdriver, url, timeout): webdriver.get(url) webdriver.execute_async_script(self.wait_script) screenshot = webdriver.get_screenshot_as_base64() # strip off the data:img/png, part of the url if screenshot.startswith("data:image/png;base64,"): screenshot = screenshot.split(",", 1)[1] return screenshot
def __init__(self, webdriver): #uva-style ID self.randomstring = (''.join(random.choice(string.ascii_lowercase) for x in range(3)) + str(random.randint(0,9)) + ''.join(random.choice(string.ascii_lowercase) for x in range(2)) ) self.name = self.randomstring self.email = self.randomstring + "@virginia.edu" print "New UserVoice with random=" + self.randomstring try: webdriver.delete_all_cookies() except WebDriverException: webdriver.get(url) webdriver.delete_all_cookies() #print "Cookies deleted" self.wb = webdriver self.broke = False self.signed = "No"
def __init__(self, webdriver): uname = ''.join(random.choice(string.ascii_lowercase) for x in range(13)) self.first_name = uname self.last_name = uname self.reason = "reasons" self.password = 123456 self.zipcode = 22904 self.address = str(random.randint(1,500)) + " " + uname + " Street" self.city = 'charlottesville' self.state = 'VA' self.email = self.last_name + "@mailinator.com" try: webdriver.delete_all_cookies() except WebDriverException: webdriver.get("http://change.org") webdriver.delete_all_cookies() self.wb = webdriver self.broke = False self.signed = "No"
def create_microcosm(server_url, webdriver, title, description): """ Prerequisite: must be viewing a site and have create permission. """ webdriver.get(server_url) create_microcosm = WebDriverWait(webdriver, 5).until( EC.element_to_be_clickable((By.ID, 'create_microcosm'))) create_microcosm.click() WebDriverWait(webdriver, 5).until( EC.element_to_be_clickable((By.ID, 'title'))).send_keys(title) WebDriverWait(webdriver, 5).until( EC.element_to_be_clickable((By.ID, 'description'))).send_keys(description) webdriver.find_element_by_id('submit').click() WebDriverWait(webdriver, 5).until( EC.element_to_be_clickable((By.ID, 'title')))
def logout(server_url, webdriver): webdriver.get(server_url) WebDriverWait(webdriver, 10).until( EC.element_to_be_clickable((By.ID, 'logout'))).click()
import sys, os from selenium import webdriver url = sys.argv[1] savein = sys.argv[2] print("Saving url " + url + " in file " + savein) chromedriver = '/usr/lib/chromium-browser/chromedriver' os.environ['webdriver.chrome.driver'] = chromedriver webdriver = webdriver.Chrome(chromedriver) webdriver.get(url) webdriver.get_screenshot_as_file(savein)
#coding=utf-8 from selenium import webdriver #引入Keys类包 driver = webdriver.Firefox() #调用火狐浏览器 driver=webdriver.Chrome() #调用chrome浏览器 driver=webdriver.Ie() #调用ie浏览器 driver=webdriver.Safari() #调用Safari浏览器 dirver= webdriver.get('c:\\program files\\internet explorer\\iexplore8.exe') #按路径打开浏览器 driver.get("http://www.baidu.com") #输入网址 driver.maximize_window() #将浏览器最大化显示 driver.set_window_size(480, 800) #设置浏览器大小 driver.back() #后退网页 driver.forward() #网页前进 driver.title #获取网页title driver.quit() #退出所有窗口 driver.close() #退出当前窗口 driver.find_element_by_id("id") #ID定位 driver.find_element_by_name("name") #name定位 driver.find_element_by_class_name("class") #class定位 driver.find_element_by_tag_name("tag_name") #标签定位 driver.find_element_by_link_text("text") #文本定位 driver.find_element_by_partial_link_text("部分文本") #部分文本定位 driver.find_element_by_xpath("xpath") #xpath定位 driver.find_element_by_xpath("//input[@id=’input’]") #通过自身的 id 属性定位 driver.find_element_by_xpath("//span[@id=’input-container’]/input") #通过上一级目录的id属性定位 driver.find_element_by_xpath("//div[@id=’hd’]/form/span/input") #通过上三级目录的 id 属性定位 driver.find_element_by_xpath("//div[@name=’q’]/form/span/input")#通过上三级目录的 name 属性定位 driver.find_element_by_css_selector("css") #css定位
def topic(self): webdriver.get(self.get_url("/")) return webdriver
def webbrowser(webdriver, url): webdriver.set_window_size(1000, 800) webdriver.get(url) return webdriver
def openurl(webdriver, suburl): print 'WD goto ', suburl webdriver.get('{domain}{suburl}'.format(domain=config.url, suburl=suburl))
from selenium import webdriver from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By #browser = Browser() fp = webdriver.FirefoxProfile() fp.set_preference("browser.download.folderList",2) fp.set_preference("browser.download.dir", "/home/dhl/download") fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream") webdriver = webdriver.Firefox(firefox_profile=fp) webdriver.get('https://nolb.dhl.de/nextt-online-business/jsp/login.do') #Loging in webdriver.find_element_by_id('login').send_keys('user') webdriver.find_element_by_id('password').send_keys('password') webdriver.find_element_by_name('doLogin').click() f = open("/home/dhl/shipment_numbers.csv") wait = WebDriverWait(webdriver, 60 * 60) for line in f: #Searching for shipment code webdriver.find_element_by_id('shipmentCode').send_keys(line) webdriver.find_element_by_id('timeIntervall').send_keys('12') webdriver.find_element_by_name('search_ta').click()
def take_screenshot(webdriver,filename,url,w=1024,h=768): webdriver.get(url) webdriver.set_window_size(w,h) return webdriver.save_screenshot(filename)