Spaces:
Running
Running
File size: 1,559 Bytes
36ef14e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import os
import random
import gradio as gr
from selenium import webdriver
from selenium_stealth import stealth
from selenium.webdriver.chrome.options import Options
def main(url):
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument("start-maximized")
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_experimental_option('useAutomationExtension', False)
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
driver = webdriver.Chrome(options=chrome_options)
stealth(
driver,
languages=["en-US", "en"],
vendor="Google Inc.",
platform="Win32",
webgl_vendor="Intel Inc.",
renderer="Intel Iris OpenGL Engine",
fix_hairline=True
)
if("https://" in url.lower() or "http://" in url.lower()):
driver.get(url)
else:
driver.get("http://" + url)
page_width = driver.execute_script("return document.body.scrollWidth")
page_height = driver.execute_script("return document.body.scrollHeight")
driver.set_window_size(page_width, page_height)
filename = str(random.randint(111111111, 999999999)) + ".png"
file_path = os.path.join(os.path.dirname(__file__), filename)
driver.save_screenshot(file_path)
return(file_path)
iface = gr.Interface(fn=main, inputs=gr.Textbox(label="URL"), outputs=[gr.Image(label="Render")])
iface.launch() |