Spaces:
Runtime error
Runtime error
Niv Sardi
commited on
Commit
•
f0a5526
1
Parent(s):
187e8b8
screenshot: support selenium remote driver
Browse files- python/screenshot.py +20 -3
python/screenshot.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
#!/usr/bin/env python3
|
2 |
#
|
3 |
-
|
4 |
import math
|
|
|
5 |
|
6 |
from selenium import webdriver
|
7 |
from selenium.webdriver.common.keys import Keys
|
@@ -15,8 +16,19 @@ from imtool import coord_dict_to_point
|
|
15 |
options = webdriver.FirefoxOptions()
|
16 |
options.add_argument("--headless")
|
17 |
options.add_argument("--window-size=1920x8000")
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
def sc_entity(e: Entity):
|
21 |
print(f'screenshoting: {e}')
|
22 |
mkdir.make_dirs([
|
@@ -27,7 +39,12 @@ def sc_entity(e: Entity):
|
|
27 |
driver.implicitly_wait(10)
|
28 |
driver.get(e.url)
|
29 |
#driver.save_screenshot(f"{defaults.DATA_PATH}/{e.bco}.png")
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
logos = driver.find_elements(By.CSS_SELECTOR, selectors.img_logo) or []
|
33 |
logos.extend(driver.find_elements(By.CSS_SELECTOR, selectors.id_logo) or [])
|
|
|
1 |
#!/usr/bin/env python3
|
2 |
#
|
3 |
+
import os
|
4 |
import math
|
5 |
+
import socket
|
6 |
|
7 |
from selenium import webdriver
|
8 |
from selenium.webdriver.common.keys import Keys
|
|
|
16 |
options = webdriver.FirefoxOptions()
|
17 |
options.add_argument("--headless")
|
18 |
options.add_argument("--window-size=1920x8000")
|
19 |
+
options.set_preference('WebglAllowWindowsNativeGl', True)
|
20 |
+
|
21 |
+
host = os.getenv('GECKO_HOST') or 'localhost'
|
22 |
+
port = os.getenv('GECKO_PORT') or '4444'
|
23 |
+
ip = socket.gethostbyname(host)
|
24 |
|
25 |
+
print(f'host: {host}->{ip}, port: {port}')
|
26 |
+
|
27 |
+
driver = webdriver.Remote(
|
28 |
+
options=options,
|
29 |
+
desired_capabilities=webdriver.DesiredCapabilities.FIREFOX,
|
30 |
+
command_executor=f"http://{ip}:{port}"
|
31 |
+
)
|
32 |
def sc_entity(e: Entity):
|
33 |
print(f'screenshoting: {e}')
|
34 |
mkdir.make_dirs([
|
|
|
39 |
driver.implicitly_wait(10)
|
40 |
driver.get(e.url)
|
41 |
#driver.save_screenshot(f"{defaults.DATA_PATH}/{e.bco}.png")
|
42 |
+
|
43 |
+
p = f"{defaults.IMAGES_PATH}/{e.bco}.full.png"
|
44 |
+
html = driver.find_element(By.TAG_NAME, 'html')
|
45 |
+
# driver.save_screenshot(p)
|
46 |
+
html.screenshot(p)
|
47 |
+
print(f'wrote: {p}')
|
48 |
|
49 |
logos = driver.find_elements(By.CSS_SELECTOR, selectors.img_logo) or []
|
50 |
logos.extend(driver.find_elements(By.CSS_SELECTOR, selectors.id_logo) or [])
|