Home > database >  How to save web page's source
How to save web page's source

Time:09-24

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
print(html)

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

CodePudding user response:

Try this:

import urllib.request
site = urllib.request.urlopen('http://somesite.com')
data = site.read()
file = open("C:\\file.txt","wb") #open file in binary mode
file.writelines(data)
file.close()

or this

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

See more details here

  • Related