Save HTML of some website in a txt file with python

后端 未结 2 1638
梦毁少年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:23

    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")
    

提交回复
热议问题