Advertisement
jarekmor

librus_playwright

Sep 13th, 2022
895
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.87 KB | Source Code | 0 0
  1. from playwright.sync_api import Playwright, sync_playwright, TimeoutError as PlaywrightTimeError
  2. from bs4 import BeautifulSoup
  3. import pandas as pd
  4.  
  5. def run(playwright: Playwright) -> None:    
  6.     browser = playwright.firefox.launch(headless=True)          #slow_mo=50
  7.     context = browser.new_context()
  8.    
  9.     # Start tracing before creating / navigating a page.
  10.     context.tracing.start(screenshots=True, snapshots=True, sources=True)
  11.    
  12.     # Open new page
  13.     page = context.new_page()
  14.    
  15.     # Go to https://portal.librus.pl/rodzina
  16.     page.goto("https://portal.librus.pl/rodzina")
  17.    
  18.     context.tracing.stop(path = "trace.zip")
  19.    
  20.     # Click text=LIBRUS Synergia >> nth=0
  21.     page.locator("text=LIBRUS Synergia").first.click()
  22.    
  23.     # Click nav >> text=Zaloguj >> nth=0
  24.     page.locator("nav >> text=Zaloguj").first.click()
  25.     page.wait_for_url("https://portal.librus.pl/rodzina/synergia/loguj")
  26.    
  27.     # Click input[name="Login"]
  28.     page.frame_locator("#caLoginIframe").locator("input[name=\"Login\"]").click()
  29.    
  30.     # Fill input[name="Login"]
  31.     page.frame_locator("#caLoginIframe").locator("input[name=\"Login\"]").fill("XXXXXXXXXXXX")       ### login
  32.    
  33.     # Click input[name="Pass"]
  34.     page.frame_locator("#caLoginIframe").locator("input[name=\"Pass\"]").click()
  35.    
  36.     # Fill input[name="Pass"]
  37.     page.frame_locator("#caLoginIframe").locator("input[name=\"Pass\"]").fill("XXXXXXXXXXXXX")       ### password
  38.    
  39.     # # Click button:has-text("Zaloguj")
  40.     page.frame_locator("#caLoginIframe").locator("button:has-text(\"Zaloguj\")").click()
  41.     page.wait_for_url("https://synergia.librus.pl/rodzic/index")
  42.     page.is_visible('div.container-background')
  43.    
  44.     # # Click #icon-oceny span
  45.     page.locator("#icon-oceny span").click()
  46.     page.wait_for_url("https://synergia.librus.pl/przegladaj_oceny/uczen")
  47.        
  48.     html_1 = page.inner_html('xpath=/html/body/div[3]/div[3]/form[1]/div/div/table/tbody')
  49.     soup = BeautifulSoup(html_1, 'html.parser')
  50.      
  51.     lista_ocen = []  
  52.     for l0 in soup.findAll('tr', {'class': 'line0'}):
  53.         slownik = {}
  54.         try:
  55.             slownik = {
  56.             #"A": l0.find_all('td')[0].text,
  57.             "B": l0.find_all('td')[1].text,
  58.             "C": l0.find_all('td')[2].text,
  59.             #"D": l0.find_all('td')[3].text,
  60.             #"E": l0.find_all('td')[4].text,
  61.             "F": l0.find_all('td')[5].text,
  62.             "G": l0.find_all('td')[6].text,
  63.             "H": l0.find_all('td')[7].text,
  64.             "I": l0.find_all('td')[8].text,
  65.             "J": l0.find_all('td')[9].text,
  66.             }
  67.            
  68.             lista_ocen.append(slownik)
  69.         except:
  70.             pass
  71.  
  72.     print(pd.DataFrame(lista_ocen))
  73.    
  74.     # ---------------------
  75.     context.close()
  76.     browser.close()
  77.    
  78. with sync_playwright() as playwright:
  79.     run(playwright)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement