-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path1indexclone.py
More file actions
29 lines (23 loc) · 797 Bytes
/
1indexclone.py
File metadata and controls
29 lines (23 loc) · 797 Bytes
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
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os
import sys
def mirror(url):
slug = url.replace('://', '_').replace('/', '_')
folder = f'mirror_{slug}'
os.makedirs(folder, exist_ok=True)
options = Options()
options.headless = True
driver = webdriver.Chrome(options=options)
driver.get(url)
# Save HTML
with open(os.path.join(folder, 'index.html'), 'w', encoding='utf-8') as f:
f.write(driver.page_source)
# Save screenshot
driver.save_screenshot(os.path.join(folder, 'screenshot.png'))
print(f'✅ Done – open {folder}/index.html')
driver.quit()
if __name__ == '__main__':
if len(sys.argv) != 2:
sys.exit('Usage: python mirror_selenium.py <url>')
mirror(sys.argv[1])