Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from playwright.sync_api import Playwright, sync_playwright, TimeoutError as PlaywrightTimeError
- from bs4 import BeautifulSoup
- import pandas as pd
- def run(playwright: Playwright) -> None:
- browser = playwright.firefox.launch(headless=True) #slow_mo=50
- context = browser.new_context()
- # Start tracing before creating / navigating a page.
- context.tracing.start(screenshots=True, snapshots=True, sources=True)
- # Open new page
- page = context.new_page()
- # Go to https://portal.librus.pl/rodzina
- page.goto("https://portal.librus.pl/rodzina")
- context.tracing.stop(path = "trace.zip")
- # Click text=LIBRUS Synergia >> nth=0
- page.locator("text=LIBRUS Synergia").first.click()
- # Click nav >> text=Zaloguj >> nth=0
- page.locator("nav >> text=Zaloguj").first.click()
- page.wait_for_url("https://portal.librus.pl/rodzina/synergia/loguj")
- # Click input[name="Login"]
- page.frame_locator("#caLoginIframe").locator("input[name=\"Login\"]").click()
- # Fill input[name="Login"]
- page.frame_locator("#caLoginIframe").locator("input[name=\"Login\"]").fill("XXXXXXXXXXXX") ### login
- # Click input[name="Pass"]
- page.frame_locator("#caLoginIframe").locator("input[name=\"Pass\"]").click()
- # Fill input[name="Pass"]
- page.frame_locator("#caLoginIframe").locator("input[name=\"Pass\"]").fill("XXXXXXXXXXXXX") ### password
- # # Click button:has-text("Zaloguj")
- page.frame_locator("#caLoginIframe").locator("button:has-text(\"Zaloguj\")").click()
- page.wait_for_url("https://synergia.librus.pl/rodzic/index")
- page.is_visible('div.container-background')
- # # Click #icon-oceny span
- page.locator("#icon-oceny span").click()
- page.wait_for_url("https://synergia.librus.pl/przegladaj_oceny/uczen")
- html_1 = page.inner_html('xpath=/html/body/div[3]/div[3]/form[1]/div/div/table/tbody')
- soup = BeautifulSoup(html_1, 'html.parser')
- lista_ocen = []
- for l0 in soup.findAll('tr', {'class': 'line0'}):
- slownik = {}
- try:
- slownik = {
- #"A": l0.find_all('td')[0].text,
- "B": l0.find_all('td')[1].text,
- "C": l0.find_all('td')[2].text,
- #"D": l0.find_all('td')[3].text,
- #"E": l0.find_all('td')[4].text,
- "F": l0.find_all('td')[5].text,
- "G": l0.find_all('td')[6].text,
- "H": l0.find_all('td')[7].text,
- "I": l0.find_all('td')[8].text,
- "J": l0.find_all('td')[9].text,
- }
- lista_ocen.append(slownik)
- except:
- pass
- print(pd.DataFrame(lista_ocen))
- # ---------------------
- context.close()
- browser.close()
- with sync_playwright() as playwright:
- run(playwright)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement