CodexSC
CodexSC

Reputation: 31

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

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

Upvotes: 2

Views: 979

Answers (1)

Prophet
Prophet

Reputation: 33371

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

Upvotes: 2

Related Questions