RBr2b22D

2021-09-13 14:16

			import pytesseract
from selenium import webdriver
from PIL import Image
from pytesseract import image_to_string
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.keys import Keys
import requests, time
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import sys
import sys
import os
from bs4 import BeautifulSoup
import requests
import urllib.request
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By




def get_captcha_text(location, size):
    pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files/Tesseract-OCR/tesseract'
    im = Image.open('screenshot.png') # uses PIL library to open image in memory

    left = location['x']
    top = location['y']
    right = location['x'] + size['width']
    bottom = location['y'] + size['height']

    im = im.crop((left, top, right, bottom))  # defines crop points
    im.save('screenshot.png')
    captcha_text = image_to_string(Image.open('screenshot.png'))
    return captcha_text


chromedriver = "C:\chromedriver"
driver = webdriver.Chrome(chromedriver)
driver.get("https://simbg.pu.go.id/dashboard")

driver.maximize_window()

driver.implicitly_wait(5)
tutup = driver.find_element_by_xpath("//*[@id='myModal']/div[3]/center/button").click()
login = driver.find_element_by_link_text("Masuk").click()
driver.implicitly_wait(5)
time.sleep(3)
element = driver.find_element_by_id('gantiimgnya') # find part of the page you want image of
location = element.location
size = element.size
driver.save_screenshot('screenshot.png')

username = driver.find_element_by_id("usernamenya").send_keys("h3ndr4s37")
password = driver.find_element_by_name("passwordnya").send_keys("dy4h4sty")

captcha = driver.find_element_by_name("cacanya")
captcha.clear()
captcha_text = get_captcha_text(location, size)
captcha.send_keys(captcha_text)
time.sleep(2)
masuk = driver.find_element_by_xpath("//*[@id='frmLogin']/div[2]/button[1]").click()