Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download an entire webpage?

When I right-click on a page in my browser, I can "Save Page As", saving the entire webpage including images, css, and js. I've seen questions answered on downloading a page's content, but this only retrieves the HTML. Is there a solution with urllib2, requests, or any other library, to downloading the complete page?

like image 621
Alon Avatar asked Feb 03 '17 22:02

Alon


Video Answer


1 Answers

You can use pyautogui coupled with selenium to achieve this.

import time
from selenium import webdriver
import pyautogui

URL = 'https://example.com'

# open page with selenium
# (first need to download Chrome webdriver, or a firefox webdriver, etc)
driver = webdriver.Chrome()
driver.get(URL)

# open 'Save as...' to save html and assets
pyautogui.hotkey('ctrl', 's')
time.sleep(1)
pyautogui.typewrite('your_filename' + '.html')
pyautogui.hotkey('enter')

Reference

like image 50
isopach Avatar answered Oct 09 '22 01:10

isopach