File size: 1,279 Bytes
485f76b
 
f1ab0d5
 
 
485f76b
 
 
 
 
 
 
 
 
 
 
f1ab0d5
 
 
f7e5bce
f1ab0d5
485f76b
 
 
f7e5bce
485f76b
f1ab0d5
 
485f76b
fc32112
 
 
f1ab0d5
485f76b
f7e5bce
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
#!/usr/bin/env python3
#

import math

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

options = webdriver.FirefoxOptions()
options.add_argument("--headless")
options.add_argument("--window-size=1920x8000")

def coord_to_point(c):
    x = math.floor(c['x'] + c['width']/2)
    y = math.floor(c['y'] + c['height']/2)
    return f"{x} {y} {math.ceil(c['width'])} {math.ceil(c['height'])}"

driver = webdriver.Firefox(options=options)
def sc_entity(e: Entity):
    print(e)
    driver.implicitly_wait(10)
    driver.get(e.url)
    driver.save_screenshot(f"{e.DATA_PATH}/{e.bco}.png")
    driver.save_full_page_screenshot(f"{e.DATA_PATH}/{e.bco}.full.png")

    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"{e.DATA_PATH}/{e.bco}.full.txt", 'w') as f:
        for i in logos:
            f.write(f"{e.bco} {coord_to_point(i.rect)}\n")

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