Save HTML of some website in a txt file with python
Easiest way would be to use urlretrieve:
import urllib
urllib.urlretrieve("http://www.example.com/test.html", "test.txt")
For Python 3.x the code is as follows:
import urllib.request
urllib.request.urlretrieve("http://www.example.com/test.html", "test.txt")
I use Python 3
.pip install requests
- after install requests
library you can save a webpage in txt file.
import requests
url = "https://stackoverflow.com/questions/24297257/save-html-of-some-website-in-a-txt-file-with-python"
r = requests.get(url)
with open('file.txt', 'w') as file:
file.write(r.text)