Save HTML of some website in a txt file with python

后端 未结 2 1650
梦毁少年i
梦毁少年i 2020-12-14 21:50

I need save the HTML code of any website in a txt file, is a very easy exercise but I have doubts with this because a have a function that do this:

import ur         


        
2条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 22:08

    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)
    

提交回复
热议问题