def pool_stat(): # open list folder and VS g = open( "C:\\Users\\hkramadhan\\PycharmProjects\\F5-Automate-Capture\\venv\\list.txt" ) for line1 in g: print("--------------------------------------------------") print("Getting Pool Statistics " + (line1)) virtualserver = line1.strip() lokasi = line1.strip() lokasi2 = "your-folder" path = lokasi2 + lokasi ob = Screenshot_Clipping.Screenshot() driver = webdriver.Chrome( executable_path= "C:\\Users\\hkramadhan\\Downloads\\Chromedriver\\chromedriver.exe") driver.get(url) driver.find_element_by_id('username').send_keys('your-account') driver.find_element_by_id('passwd').send_keys('your-password') driver.find_element_by_xpath("//*[@id='loginform']/button").click() detail = "/tmui/Control/jspmap/tmui/locallb/virtual_server/resources.jsp?name=/Common/" new_page = url + detail + virtualserver driver.get(new_page) driver.maximize_window() time.sleep(1) driver.switch_to.frame("contentframe") user_selected = Select( driver.find_element_by_xpath('//*[@id="default_pool"]')) print(user_selected.first_selected_option.text.replace(" ", "")) mantul = user_selected.first_selected_option.text.replace(" ", "") if mantul.strip('\n') == 'None': driver.close() driver.quit() print("Pool tidak ditemukan rekan :(") spasi = ' ' print(20 * spasi) else: driver.switch_to.default_content() detail2 = "/tmui/Control/jspmap/tmui/locallb/pool/stats.jsp?name=/Common/" next_page = url + detail2 + mantul print(next_page) driver.get(next_page) driver.maximize_window() time.sleep(5) element = driver.find_element_by_xpath('//*[@id="contentframe"]') """img_url = ob.full_Screenshot(driver, save_path=path, image_name='pool_stat.png')""" img_url = ob.get_element(driver, element, path) print(img_url) spasi = ' ' print(20 * spasi) driver.close() driver.quit()
def vs_properties(): # open list folder and VS g = open("your-file-path") for line1 in g: print("--------------------------------------------------") print("Getting Virtual Server Properties " + (line1)) virtualserver = line1.strip() lokasi = line1.strip() lokasi2 = "your-folder" path = lokasi2 + lokasi ob = Screenshot_Clipping.Screenshot() driver = webdriver.Chrome(executable_path="C:\\Users\\hkramadhan\\Downloads\\Chromedriver\\chromedriver.exe") driver.get(url) driver.find_element_by_id('username').send_keys('username') driver.find_element_by_id('passwd').send_keys('passwd') driver.find_element_by_xpath("//*[@id='loginform']/button").click() detail = "/tmui/Control/jspmap/tmui/locallb/virtual_server/properties.jsp?name=/Common/" new_page = url + detail + virtualserver driver.get(new_page) driver.maximize_window() time.sleep(1) img_url = ob.full_Screenshot(driver, save_path=path, image_name='vs_properties.png') print(img_url) spasi = ' '; print(20*spasi) driver.close() driver.quit()
def dashboard(): ob = Screenshot_Clipping.Screenshot() driver = webdriver.Chrome( executable_path= "C:\\Users\\hkramadhan\\Downloads\\Chromedriver\\chromedriver.exe") driver.get(url) driver.find_element_by_id('username').send_keys('username') driver.find_element_by_id('passwd').send_keys('passwd') driver.find_element_by_xpath("//*[@id='loginform']/button").click() detail = "/tmui/dashboard/F5Dashboard.html" new_page = pelengkap + ipaddress + detail print(new_page) print(path) driver.get(new_page) driver.fullscreen_window() time.sleep(80) img_url = ob.full_Screenshot(driver, save_path=path, image_name='dashboard.png') print(img_url) driver.close() driver.quit()
def network(): ob = Screenshot_Clipping.Screenshot() driver = webdriver.Chrome( executable_path= "C:\\Users\\hkramadhan\\Downloads\\Chromedriver\\chromedriver.exe") driver.get(url) driver.find_element_by_id('username').send_keys('username') driver.find_element_by_id('passwd').send_keys('passwd') driver.find_element_by_xpath("//*[@id='loginform']/button").click() detail = "/tmui/Control/jspmap/tmui/overview/stats/network.jsp?reset_section_list=true" new_page = pelengkap + ipaddress + detail print(new_page) print(path) driver.get(new_page) driver.maximize_window() driver.switch_to.frame("contentframe") driver.find_element_by_xpath( "//*[@id='section_div']/table[2]/tbody/tr/td[2]/div/select/option[contains(text(), 'Show')]" ).click() driver.switch_to.default_content() time.sleep(7) img_url = ob.full_Screenshot(driver, save_path=path, image_name='network.png') print(img_url) driver.close() driver.quit()
def get_result(curr_roll): try: driver.get("https://mis.nitrr.ac.in/publishedresult.aspx") roll = driver.find_element_by_id("txtRegno") roll.send_keys(curr_roll) roll.send_keys(Keys.ENTER) time.sleep(2) nameel = driver.find_element_by_xpath('//*[@id="lblSName"]') name = nameel.text sem = driver.find_element_by_xpath('//*[@id="ddlSemester"]/option[2]') sem.click() #time.sleep(5) show = driver.find_element_by_id('btnimgShowResult') show.click() time.sleep(2) driver.execute_script( "window.scrollTo(0, document.body.scrollHeight);") s = driver.find_element_by_xpath( '//*[@id="form1"]/table[2]/tbody/tr[1]/td') ob = Screenshot_Clipping.Screenshot() img_url = ob.get_element(driver, s, r'.') print(img_url) #driver.quit() except: NoSuchElementException
def performance(): ob = Screenshot_Clipping.Screenshot() driver = webdriver.Chrome( executable_path= "C:\\Users\\hkramadhan\\Downloads\\Chromedriver\\chromedriver.exe") driver.get(url) driver.find_element_by_id('username').send_keys('username') driver.find_element_by_id('passwd').send_keys('passwd') driver.find_element_by_xpath("//*[@id='loginform']/button").click() detail = "/tmui/Control/jspmap/tmui/system/stats/list.jsp?subset=All" new_page = pelengkap + ipaddress + detail print(new_page) print(path) driver.get(new_page) driver.maximize_window() time.sleep(5) img_url = ob.full_Screenshot(driver, save_path=path, image_name='performance.png') print(img_url) driver.close() driver.quit()
def fullpage_screenshot(): # chrome_options = Options() # chrome_options.add_argument('--headless') # chrome_options.add_argument('--start-maximized') DRIVER = 'chromedriver' driver = webdriver.Chrome(DRIVER) driver.get('http://dradio.kbs.co.kr') time.sleep(5) # original_size = driver.get_window_size() required_width = driver.execute_script('return document.body.parentNode.scrollWidth') required_height = driver.execute_script('return document.body.parentNode.scrollHeight') # print(str(required_width) + " " + str(required_height)) driver.set_window_size(1800,4500) ob=Screenshot_Clipping.Screenshot() # page_body = driver.find_element_by_tag_name('body') # driver.set_window_size() # page_body.screenshot('./output/my_screenshot.png') img_url=ob.full_Screenshot(driver,save_path=r'./output', image_name='my_screenshot.png') # screenshot = driver.save_screenshot('./output/my_screenshot.png') # screenshot = driver.save_screenshot('./output/my_screenshot.png') driver.close() driver.quit()
def screen_cap(self): full_screen = Screenshot_Clipping.Screenshot() file_name = '' if os.path.isfile(self.get_cap_name()): file_name = self.get_cap_name().replace('.', '(copy).') else: file_name = self.get_cap_name() full_screen.full_Screenshot(self.driver, self.file_path, file_name)
def take_screenshot(self, image_name): path = self.__get_screenshots_folder_path() now = datetime.now() timestamp = datetime.timestamp(now) ss_obj = Screenshot_Clipping.Screenshot() ss_obj.full_Screenshot(self.__web_driver, save_path=path, image_name=f"{image_name}_{timestamp}.png")
def test_HelloWorld(self): driver = self.driver ob = Screenshot_Clipping.Screenshot() url = "https://www.larepublica.co/robots.txt." self.driver.get(url) img_url = ob.full_Screenshot( driver, save_path=r'.', image_name='ScreenShot.png') print(img_url) driver.close()
def test_full_screenshot(): ob = Screenshot_Clipping.Screenshot() driver = webdriver.Chrome(executable_path=chromedriver_path) # url = "https://github.com/sam4u3/Selenium_Screenshot/tree/master/test" url = 'http://yandex.ru' driver.get(url) img_url = ob.full_Screenshot(driver, save_path=r'.',image_name='Myimage.png',is_load_at_runtime=True,load_wait_time=3) os.remove(img_url) driver.close() driver.quit()
def grab_full_page(url): ob = Screenshot_Clipping.Screenshot() driver = webdriver.Firefox() driver.get(url) driver.maximize_window() driver.find_element_by_xpath( '/html/body/div[1]/div/div/div/div[2]/div/div[3]/div[1]/div[2]/div[*]/div/button' ).click() img_url = ob.full_Screenshot(driver, save_path='.') print(img_url) driver.close() driver.quit()
def test_hide_element(): ob = Screenshot_Clipping.Screenshot() driver = webdriver.Chrome(executable_path=chromedriver_path) url = "https://github.com/sam4u3" driver.get(url) Hide_elements = ['class=avatar width-full height-full avatar-before-user-status'] # Use full class name img_url = ob.full_Screenshot(driver, save_path=r'.', elements=Hide_elements, image_name='Myimage.png') os.remove(img_url) driver.close() driver.quit()
def mk_scrnsht(self): ob = Screenshot_Clipping.Screenshot() url = self.driver.current_url today = time.strftime(f'%Y_%m_%d') now = time.strftime(f'%H_%M_%S') file_name = 'vulnerability_' + today + '_' + now + '.jpg' img_url = ob.full_Screenshot( self.driver, save_path= r'C:\Everything\IT\Testing\Automation_08_09_2019\autocareparts_gene_kayakov\screen_shots', image_name=file_name) print(img_url)
def test_element_screenshot(): ob = Screenshot_Clipping.Screenshot() driver = webdriver.Chrome(executable_path=chromedriver_path) url = "https://github.com/sam4u3/Selenium_Screenshot/blob/master/Screenshot/Screenshot_Clipping.py" driver.get(url) element = driver.find_element_by_class_name('signup-prompt') img_url = ob.get_element(driver, element, r'.') os.remove(img_url) driver.close() driver.quit()
def ext_img(ext_id): if not os.path.isfile('./static/img/exts/'+ext_id+'.png'): ob=Screenshot_Clipping.Screenshot() driver = webdriver.Chrome() url = "https://chrome.google.com/webstore/detail/z/"+ext_id driver.get(url) file_path = "./static/img/exts/"+ext_id+".png" time.sleep(2) print(file_path) driver.save_screenshot(file_path) driver.close() driver.quit() print("Saved image!")
def take_screenshot(name): Hide_elements = [ 'class= masthead row', 'class= sticky-container', 'id=global-footer', 'id=local-footer', 'class=actions', 'class=small pop-button right', 'class=meta', 'id=subnav', 'class=float-right reuse button small', 'class=notify nojshide release-info important', 'class=columns small-6 medium-6', 'class=left' ] ob = Screenshot_Clipping.Screenshot() img_url = ob.full_Screenshot(driver, save_path=r'', elements=Hide_elements, image_name=name) print(img_url)
def take_full_screenshot(driver, scenario_name): if (driver == None): return None driver.maximize_window() from Screenshot import Screenshot_Clipping screen_img_path = "./result/screenshot/" img_file_name = str(time.time()) img_file_name = img_file_name + ".png" browserScreenShot = Screenshot_Clipping.Screenshot() img_url = browserScreenShot.full_Screenshot(driver, save_path=screen_img_path, image_name=img_file_name) #print(img_url) #allure.attach.file(source=img_url, name=scenario_name, attachment_type=AttachmentType.PNG) allure.attach.file(img_url, attachment_type=AttachmentType.PNG)
def screenshotMatchpage(match): ob = Screenshot_Clipping.Screenshot() driver = webdriver.Chrome('E:\chromedriver.exe') url = match driver.get(url) time.sleep(1) submit_button = driver.find_elements_by_xpath( '/html/body/div[1]/div/div/div/div[2]/div[2]/div[1]/button[2]')[0] submit_button.click() img_url = ob.full_Screenshot(driver, save_path=r'C:\Users\krang\Desktop\matches', image_name='Myimage.png') driver.close() driver.quit() im = Image.open(r'C:\Users\krang\Desktop\matches\myImage.png') cropped = im.crop((0, 150, 928, 600)) cropped.save(r'C:\Users\krang\Desktop\matches\myImage.png')
def fullpage_screenshot(): # chrome_options = Options() # chrome_options.add_argument('--headless') # chrome_options.add_argument('--start-maximized') DRIVER = 'chromedriver' driver = webdriver.Chrome(DRIVER) driver.get('http://radio.kbs.co.kr') time.sleep(5) # print(str(required_width) + " " + str(required_height)) driver.set_window_size(1800, 4500) ob = Screenshot_Clipping.Screenshot() filename = datetime.today().strftime("%m%d%H%M%S") + "screenshot.png" img_url = ob.full_Screenshot(driver, save_path=r'./output', image_name=filename) driver.close() driver.quit()
def vserver(): ob = Screenshot_Clipping.Screenshot() driver = webdriver.Chrome( executable_path= "C:\\Users\\hkramadhan\\Downloads\\Chromedriver\\chromedriver.exe") url = "https://your-ip/" driver.get(url) driver.find_element_by_id('username').send_keys('your-username') driver.find_element_by_id('passwd').send_keys('your-passwd') driver.find_element_by_xpath("//*[@id='loginform']/button").click() new_page = "https://your-ip/tmui/Control/jspmap/tmui/locallb/virtual_server/list.jsp" driver.get(new_page) driver.maximize_window() time.sleep(5) img_url = ob.full_Screenshot( driver, save_path='C:\\Users\\hkramadhan\\Downloads\\your-folder\\', image_name='vserver.png') print(img_url) driver.close() driver.quit()
def dashboard(): ob = Screenshot_Clipping.Screenshot() driver = webdriver.Chrome( executable_path= "C:\\Users\\hkramadhan\\Downloads\\Chromedriver\\chromedriver.exe") url = "https://your-ip/" driver.get(url) driver.find_element_by_id('username').send_keys('your-username') driver.find_element_by_id('passwd').send_keys('your-passwd') driver.find_element_by_xpath("//*[@id='loginform']/button").click() new_page = "https://your-ip/tmui/dashboard/F5Dashboard.html" driver.get(new_page) driver.fullscreen_window() time.sleep(80) img_url = ob.full_Screenshot( driver, save_path='C:\\Users\\hkramadhan\\Downloads\\your-folder\\', image_name='dashboard.png') print(img_url) driver.close() driver.quit()
def monitor_properties(): # open list folder and VS g = open("C:\\Users\\hkramadhan\\PycharmProjects\\F5-Automate-Capture\\venv\\list.txt") for line1 in g: print("--------------------------------------------------") print("Getting Monitor Properties " + (line1)) virtualserver = line1.strip() lokasi = line1.strip() lokasi2 = "your-folder" path = lokasi2 + lokasi ob = Screenshot_Clipping.Screenshot() driver = webdriver.Chrome(executable_path="C:\\Users\\hkramadhan\\Downloads\\Chromedriver\\chromedriver.exe") driver.get(url) # Masuk ke halaman awal F5 untuk login driver.find_element_by_id('username').send_keys('your-account') driver.find_element_by_id('passwd').send_keys('your-password') driver.find_element_by_xpath("//*[@id='loginform']/button").click() detail = "/tmui/Control/jspmap/tmui/locallb/virtual_server/resources.jsp?name=/Common/" new_page = url + detail + virtualserver # Masuk ke halaman virtual server driver.get(new_page) driver.maximize_window() time.sleep(1) # Membaca text dari option yang dipilih driver.switch_to.frame("contentframe") user_selected = Select(driver.find_element_by_xpath('//*[@id="default_pool"]')) print(user_selected.first_selected_option.text.replace(" ", "")) mantul = user_selected.first_selected_option.text.replace(" ", "") # Jika text dari option adalah None, langsung keluar, jika tidak masuk ke halaman pool if mantul.strip('\n') == 'None': driver.close() driver.quit() print("Pool tidak ditemukan rekan :(") spasi = ' '; print(20 * spasi) else: driver.switch_to.default_content() detail2 = "/tmui/Control/jspmap/tmui/locallb/pool/properties.jsp?name=/Common/" next_page = url + detail2 + mantul print(next_page) # Masuk ke halaman pool driver.get(next_page) driver.maximize_window() time.sleep(2) driver.switch_to.frame("contentframe") driver.find_element_by_xpath('//*[@id="/tmui/locallb/pool/properties.jsp?.configuration_tabletoggle"]/option[2]').click() time.sleep(2) # Membaca health monitor yang dipilih print(driver.find_element_by_xpath('//*[@id="monitor_rule/Common"]').text.replace(" ", "")) yuhu = driver.find_element_by_xpath('//*[@id="monitor_rule/Common"]').text.replace(" ", "") # Menuju halaman health monitor properties driver.switch_to.default_content() detail3 = "/tmui/Control/jspmap/tmui/locallb/monitor/properties.jsp?name=/Common/" hal_berikut = url + detail3 + yuhu print(hal_berikut) driver.get(hal_berikut) driver.maximize_window() time.sleep(2) # Memilih advanced option dari health monitor properties driver.switch_to.frame("contentframe") detail4 = '//*[@id="/tmui/locallb/monitor/properties.jsp?name=/Common/' aye = '.configuration_tabletoggle"]/option[2]' yuhu2 = yuhu.replace("\n", "") top = detail4 + yuhu2 + aye print(top) driver.find_element_by_xpath(top).click() time.sleep(2) driver.switch_to.default_content() time.sleep(2) element = driver.find_element_by_xpath('//*[@id="contentframe"]') img_url = ob.get_element(driver, element, path) """img_url = ob.full_Screenshot(driver, save_path=path, image_name='monitor_properties.png')""" print(img_url) spasi = ' '; print(20*spasi) driver.close() driver.quit()
def screenshot_element(driver, element, file_name): ob = Screenshot_Clipping.Screenshot() temp_path = Path(ob.get_element(driver, element, ".")) temp_path.rename(file_name) (temp_path.parents[0] / "clipping_shot.png").unlink() print(f"wrote element screenshot to {file_name}")
def run_selenium_server(driver): driver.get("http://www.python.org") # Store the ID of the original window original_window = driver.current_window_handle # Access each dimension individually position = driver.get_window_position() msg_pos = 'Window position: ' + str(position) print(msg_pos) x = position.get('x') y = position.get('y') # Or store the dimensions and query them later size = driver.get_window_size() width = size.get("width") height = size.get("height") print('Window size: ' + str(size)) print('Width: ' + str(width)) print('Height: ' + str(height)) driver.set_window_size(1024, 768) size = driver.get_window_size() width = size.get("width") height = size.get("height") print('Window size: ' + str(size)) print('Width: ' + str(width)) print('Height: ' + str(height)) # Check we don't have other windows open already assert len(driver.window_handles) == 1 assert "Python" in driver.title print("Page: " + driver.title) elem = driver.find_element_by_name("q") elem.send_keys("selenium") elem.send_keys(Keys.RETURN) record = driver.find_element_by_xpath( '//*[@id="content"]/div/section/form/ul/li[1]/h3/a') record.click() record2 = driver.find_element_by_xpath( '//*[@id="content"]/div/section/article/div[2]/p[2]/span[2]/a') record2.click() record3 = driver.find_element_by_xpath('//*[@id="top"]/nav/ul/li[3]/a') record3.click() driver.get("http://www.google.com") print("Page: " + driver.title) text_search = driver.find_element_by_name("q") text_search.send_keys("edit forms") text_search.send_keys(Keys.RETURN) rec_search = driver.find_element_by_xpath( '//*[@id="rso"]/div[9]/div/div[1]/a/h3') rec_search.click() print("Page: " + driver.title) # Open URL driver.get("https://seleniumhq.github.io") print("Page: " + driver.title) # Loop through until we find a new window handle for window_handle in driver.window_handles: if window_handle != original_window: driver.switch_to.window(window_handle) break # open new blank tab driver.execute_script("window.open();") # Opens a new tab and switches to new tab driver.switch_to.window(driver.window_handles[1]) driver.get("http://www.msn.it") print("Page: " + driver.title) driver.find_element_by_xpath( '//*[@id="main"]/div[3]/div/div/div[3]/ul/li[7]/a').click() time.sleep(5) driver.back() time.sleep(5) driver.forward() time.sleep(5) driver.get( 'https://www.almaviva.it/it_IT/Societa-del-gruppo/AlmavivA_Digitaltec') print("Page: " + driver.title) ob = Screenshot_Clipping.Screenshot() element = driver.find_element_by_xpath('/html/body/div/div[8]/a/span') if element.is_displayed() == True: WebDriverWait(driver, 20).until( EC.element_to_be_clickable( (By.XPATH, "/html/body/div/div[8]/a/span"))).click() elem = driver.find_element_by_xpath( '/html/body/div/div[5]/div[1]/picture/img') if os.path.isdir('./images') == False: os.mkdir('images') img_url = ob.get_element(driver, elem, 'images') #print(img_url) os.chdir('images') os.remove('clipping_shot.png') head_tail = os.path.split(img_url) os.rename(head_tail[1], 'palace.png') print(head_tail[0] + '\\palace.png') else: shutil.rmtree('images', ignore_errors=True) os.mkdir('images') img_url = ob.get_element(driver, elem, 'images') #print(img_url) os.chdir('images') os.remove('clipping_shot.png') head_tail = os.path.split(img_url) img = 'palace.png' os.rename(head_tail[1], img) print(head_tail[0] + '\\' + img)
from Screenshot import Screenshot_Clipping from selenium import webdriver import time wd = webdriver.Chrome() url = 'https://cn.bing.com/search?q=Selenium-Screenshot+github&qs=n&form=QBLHCN&sp=-1&pq=selenium-screenshot+git&sc=0-23&sk=&cvid=E4B25D5FBD7F471E8BDDF8ECBD1DED94' wd.implicitly_wait(10) wd.get(url) ob = Screenshot_Clipping.Screenshot() img_url = ob.full_Screenshot(wd, save_path=r'.', image_name='Myimage.png') print(img_url) wd.close() wd.quit()
print('COURSE CODE ATTD/TOT ATTD %') print('--------------------------------') for row in rows: col = row.find_elements(By.TAG_NAME, 'td') for c in col: print(c.text,'\t',end=' ') print() print('--------------------------------') print('TOTAL ATTENDANCE %:\t ',end='') print(WebDriverWait(driver,30).until( EC.presence_of_element_located((By.ID,'ContentPlaceHolder1_lblTotal')) ).text) print('--------------------------------') print() SS_FOLDER = f'{FILE_PATH}/Screenshots' if not os.path.exists(SS_FOLDER): os.makedirs(SS_FOLDER) k = Screenshot_Clipping.Screenshot().get_element(driver,WebDriverWait(driver,30).until( EC.presence_of_element_located((By.ID,'ContentPlaceHolder1_tblAttendance')) ),r'./Screenshots') os.remove(os.path.join(SS_FOLDER,'clipping_shot.png')) ssname = f'{usr}_{datetime.now().strftime("%d-%m-%Y_%H%M%S")}' os.rename(os.path.join(SS_FOLDER,k),os.path.join(SS_FOLDER,ssname)) finally: driver.quit()
def scrape_sections(page): """ Will scrape sections data from the given page code and update it to the airtable and space """ fields = page.get('fields') code, pack, page_name, niche, page_url = fields.get('Page Code'), fields.get('Pack'), fields.get( 'Page'), fields.get('Niche'), fields.get('Page Url') code_url = code[0].get('url') page_code = DiviPages.get_page_code(url=code_url) page_live_url = page_url + "/live-demo" chrome_options = ChromeOptions() chrome_options.headless = False driver = Chrome(chrome_options=chrome_options, executable_path=CHROME_WEBDRIVER) driver.get(page_live_url) time.sleep(2) driver.maximize_window() total_sections = driver.execute_script("return document.querySelectorAll('.et_pb_section').length") # for loading all lazy images SCROLL_PAUSE_TIME = 0.5 i = 0 last_height = driver.execute_script("return document.body.scrollHeight") while True: driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") time.sleep(SCROLL_PAUSE_TIME) new_height = driver.execute_script("return document.body.scrollHeight") if new_height == last_height: break last_height = new_height i += 1 if i == 5: break driver.implicitly_wait(10) for i in range(0, total_sections): fields = page.get('fields') code, pack, page_name, niche, page_url = fields.get('Page Code'), fields.get('Pack'), fields.get( 'Page'), fields.get('Niche'), fields.get('Page Url') code_url = code[0].get('url') page_code = DiviPages.get_page_code(url=code_url) page_live_url = page_url + "/live-demo" section_name = f"{pack}-{page_name}-section-{i}.png" section_code_name = f"{pack}-{page_name}-section-{i}.json" name = f"{pack}-{page_name}-section-{i}" try: # injecting css code driver.execute_script(""" let injectedScript = document.querySelector("#scraper-script"); if ( injectedScript ) { injectedScript.parentNode.removeChild(injectedScript); } let bodyElement = document.querySelector('head') bodyElement.innerHTML = `<style id="scraper-script"> * { animation-duration: 0s !important; animation-delay: 0s !important; } #page-container { padding: 0px !important; } #main-footer, #main-header { display:none !important; } .et_pb_section:not(.et_pb_section_%s) { display: none !important; } .et_animated.et-waypoint { opacity: 1 !important; } .et_animated { opacity: 1 !important; } .et_had_animation.et-waypoint { animation-duration: 0s !important; animation-delay: 0s !important; } </style> ${bodyElement.innerHTML} ` """ % (str(i))) section_element = driver.find_element_by_class_name(f"et_pb_section_{i}") root_save_path = TMP_DIRECTORY + f"/{pack}/{page_name}" screenshot_save_path = root_save_path + "/" + section_name # creating dir if not found if not os.path.exists(root_save_path): os.makedirs(root_save_path) ob = Screenshot_Clipping.Screenshot() ob.get_element( driver=driver, element=section_element, save_location=root_save_path, name=section_name ) section_shortcode, section_code = DiviSections.get_code(page_code, i, f"{pack}-{page_name}-section-{i}") code_save_path_root = TMP_DIRECTORY + f"/{pack}/{page_name}" code_save_path_full = code_save_path_root + f"/{section_code_name}" # creating a json content file if not found if not os.path.exists(code_save_path_full): open(code_save_path_full, "x") with open(code_save_path_full, 'r+') as code_file: overwrite_file(code_file, json.dumps(section_shortcode)) code_file.close() # from further this line i've both code/section # uploading media to space because airtable attaches # media by reading publicly readable/available endpoints space = Space() # uploading image is_image_uploaded = space.upload(path=screenshot_save_path, public_id=name + ".jpg", c_type="image/jpeg") # uploading code is_code_uploaded = space.upload(path=code_save_path_full, public_id=section_code_name, c_type="application/json") if is_image_uploaded == False or is_code_uploaded == False: raise SystemExit('Failed to upload code or image to the space') # deleting them from os because media has been uploaded to the space for media_path in [screenshot_save_path, code_save_path_full]: if os.path.exists(media_path): os.remove(media_path) screenshot_uploaded_url = space.proxy + name + ".jpg" code_uploaded_url = space.proxy + section_code_name # adding section to airtable response = Airtable.post_section(section={ 'Title': name, 'Pack': pack, 'Section Screenshot': screenshot_uploaded_url, 'Section Code': code_uploaded_url, 'Page': page_name, 'Niche': niche, 'Url': page_url, 'Modules': get_module_names(section_code) }) # deleting media for media_path in [screenshot_save_path, code_save_path_full]: if os.path.exists(media_path): os.remove(media_path) if response != True: raise SystemExit('Failed to add sections in airtable') except NoSuchElementException: pass # this means section has been published successfully # updating progress with open(DIVI_SECTION_PROGRESS_PATH, 'r+') as section_progress_file: current_section_progress = json.load(section_progress_file) if page_name not in current_section_progress: current_section_progress.append(page_name) overwrite_file(section_progress_file, json.dumps(current_section_progress)) section_progress_file.close() driver.quit()