Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from playwright.sync_api import Playwright, sync_playwright, expect
- from bs4 import BeautifulSoup
- import requests
- import json
- def run(playwright: Playwright) -> None:
- browser = playwright.chromium.launch(headless=True)
- context = browser.new_context()
- page = context.new_page()
- page.goto("http://wojszym2244.usermd.net/")
- page.locator("img[alt=\"Zaloguj\"]").click()
- page.locator("[placeholder=\"Wprowadź ID wpisane do sterownika\"]").click()
- page.locator("[placeholder=\"Wprowadź ID wpisane do sterownika\"]").fill("1000000000") # <- to wpisać ID
- page.locator("[placeholder=\"Wprowadź Nick zapisany na stronie\"]").click()
- page.locator("[placeholder=\"Wprowadź Nick zapisany na stronie\"]").fill("test") # <- to wpisać nick
- page.locator("[placeholder=\"Wprowadź PIN wpisany do sterownika\"]").click()
- page.locator("[placeholder=\"Wprowadź PIN wpisany do sterownika\"]").fill("1234") # <- to wpisać PIN
- page.locator("text=Login").click()
- # ---------------------
- # od tego miejsca można scrapować np. z wykorzystanem BeautifulSoup
- html = page.content()
- soup = BeautifulSoup(html, 'html.parser')
- butotalfuel = soup.select('#butotalfuel')
- bu24hfuel = soup.select('#bu24hfuel')
- buactualfuel = soup.select('#buactualfuel')
- OpalStan = soup.select('#OpalStan')
- OpalZostaloDni= soup.select('#OpalZostaloDni')
- json_table = {"butotalfuel": float(butotalfuel[0].text),
- "bu24hfuel": float(bu24hfuel[0].text),
- "buactualfuel": float(buactualfuel[0].text),
- "OpalStan": float(OpalStan[0].text[:-2]),
- "OpalZostaloDni": int(OpalZostaloDni[0].text[:-1])}
- json_object = json.dumps(json_table, indent = 4)
- # zapis json do pliku piec.json
- with open("piec.json", "w") as outfile:
- outfile.write(json_object)
- context.close()
- browser.close()
- with sync_playwright() as playwright:
- run(playwright)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement