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