-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrap.py
32 lines (26 loc) · 960 Bytes
/
scrap.py
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
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
def test_fullpage_screenshot(url: str, filename: str):
options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--disable-gpu')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--headless')
options.add_argument('--start-maximized')
driver = webdriver.Chrome(options=options)
try:
driver.get(url)
time.sleep(2)
ele = driver.find_element(By.TAG_NAME, 'body')
height = driver.execute_script("return document.body.scrollHeight")
driver.set_window_size(1920, height)
driver.save_screenshot(f"screenshots/{filename}")
except Exception:
pass
finally:
driver.close()
driver.quit()
if __name__ == "__main__":
test_fullpage_screenshot("https://vk.com/", "vk.png")