How to save web page's source


Hello i want save web page’s source codes to any any text file and saving it C:\ folder.

I tried get web page’s source with this code:

html = driver.page_source

How to save page source to C:\ folder in a text file?


Try this:

import urllib.request
site = urllib.request.urlopen('')
data =
file = open("C:\\file.txt","wb") #open file in binary mode

or this

import urllib.request
def extractHTML(url):
    urllib.request.urlretrieve(url, 'C:\\file.txt')

See more details here

Answered By – Prophet

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published