Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -49,8 +49,8 @@ def run_script(url: str, height: int, width: int, check_b,check_h):
|
|
49 |
mes='<center>operation success'
|
50 |
try:
|
51 |
driver = webdriver.Chrome(options=options)
|
52 |
-
driver.current_window_handle
|
53 |
-
|
54 |
html=driver.page_source
|
55 |
print(html)
|
56 |
driver.implicitly_wait(30)
|
@@ -99,6 +99,38 @@ def run_script(url: str, height: int, width: int, check_b,check_h):
|
|
99 |
else:
|
100 |
return None, '<center>Please enter a valid URL of a website/host.',out_box,out
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
with gr.Blocks() as app:
|
103 |
|
104 |
with gr.Row():
|
|
|
49 |
mes='<center>operation success'
|
50 |
try:
|
51 |
driver = webdriver.Chrome(options=options)
|
52 |
+
#driver.current_window_handle
|
53 |
+
driver.get(url)
|
54 |
html=driver.page_source
|
55 |
print(html)
|
56 |
driver.implicitly_wait(30)
|
|
|
99 |
else:
|
100 |
return None, '<center>Please enter a valid URL of a website/host.',out_box,out
|
101 |
|
102 |
+
def run_script(url: str, height: int, width: int, check_b,check_h):
|
103 |
+
mes_box=[]
|
104 |
+
out_box=[]
|
105 |
+
uid=uuid.uuid4()
|
106 |
+
out=None
|
107 |
+
is_url=True
|
108 |
+
if is_url:
|
109 |
+
options = webdriver.ChromeOptions()
|
110 |
+
options.add_argument('--headless')
|
111 |
+
options.add_argument('--no-sandbox')
|
112 |
+
options.add_argument('--disable-dev-shm-usage')
|
113 |
+
mes='<center>operation success'
|
114 |
+
try:
|
115 |
+
driver = webdriver.Chrome(options=options)
|
116 |
+
driver.current_window_handle
|
117 |
+
#driver.get(url)
|
118 |
+
html=driver.page_source
|
119 |
+
print(html)
|
120 |
+
driver.implicitly_wait(30)
|
121 |
+
driver.set_window_size(int(width), int(height))
|
122 |
+
|
123 |
+
screenshot = driver.screenshot(f'{uid}-tmp.png')
|
124 |
+
except WebDriverException as e:
|
125 |
+
return Image.new('RGB', (1, 1)), f'<center>Please enter a valid URL of a website/host.',out_box,out
|
126 |
+
finally:
|
127 |
+
if driver:
|
128 |
+
driver.quit()
|
129 |
+
return Image.open(f'{uid}-tmp.png'), mes,out_box,out
|
130 |
+
else:
|
131 |
+
return None, '<center>Please enter a valid URL of a website/host.',out_box,out
|
132 |
+
|
133 |
+
|
134 |
with gr.Blocks() as app:
|
135 |
|
136 |
with gr.Row():
|