File size: 1,781 Bytes
485f76b
 
f0a5526
f1ab0d5
f0a5526
f1ab0d5
485f76b
 
 
 
 
 
ae7097b
8f69832
485f76b
 
 
 
f0a5526
 
 
 
 
485f76b
f0a5526
 
 
 
 
 
 
485f76b
ae7097b
 
 
 
 
 
f7e5bce
485f76b
ae7097b
f0a5526
 
 
 
 
 
485f76b
fc32112
 
 
ae7097b
485f76b
8f69832
485f76b
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
#
import os
import math
import socket

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

from common import selectors
from entity import Entity
from common import defaults,mkdir
from imtool import coord_dict_to_point

options = webdriver.FirefoxOptions()
options.add_argument("--headless")
options.add_argument("--window-size=1920x8000")
options.set_preference('WebglAllowWindowsNativeGl', True)

host = os.getenv('GECKO_HOST') or 'localhost'
port = os.getenv('GECKO_PORT') or '4444'
ip = socket.gethostbyname(host)

print(f'host: {host}->{ip}, port: {port}')

driver = webdriver.Remote(
    options=options,
    desired_capabilities=webdriver.DesiredCapabilities.FIREFOX,
    command_executor=f"http://{ip}:{port}"
)
def sc_entity(e: Entity):
    print(f'screenshoting: {e}')
    mkdir.make_dirs([
            defaults.IMAGES_PATH,
            defaults.LABELS_PATH,
    ])

    driver.implicitly_wait(10)
    driver.get(e.url)
    #driver.save_screenshot(f"{defaults.DATA_PATH}/{e.bco}.png")

    p = f"{defaults.IMAGES_PATH}/{e.bco}.full.png"
    html = driver.find_element(By.TAG_NAME, 'html')
    # driver.save_screenshot(p)
    html.screenshot(p)
    print(f'wrote: {p}')

    logos = driver.find_elements(By.CSS_SELECTOR, selectors.img_logo) or []
    logos.extend(driver.find_elements(By.CSS_SELECTOR, selectors.id_logo) or [])
    logos.extend(driver.find_elements(By.CSS_SELECTOR, selectors.cls_logo) or [])
    with open(f"{defaults.LABELS_PATH}/{e.bco}.full.txt", 'w') as f:
        for i in logos:
            f.write(f"{e.id} {coord_dict_to_point(i.rect)}\n")

if __name__ == '__main__':
    sc_entity(Entity.from_dict({'url': 'http://www.bbva.com.ar', 'bco': 'debug'}))