官术网_书友最值得收藏!

With Python 2

  1. First, import the required module, urllib:
>>> import urllib  
  1. With the urlopen method, you can download the web page:
>>> webpage = urllib.urlopen("https://www.packtpub.com/")  
  1. We can read the file like a returned object with the read method:
>>> source =  webpage.read()  
  1. Close the object when it's done:
>>>  webpage.close()  
  1. Now we can print the HTML, which is in a string format:
>>> print source  
  1. It is very easy to update the program to write the contents of the source string to a local file on your computer:
>>> f = open('packtpub-home.html', 'w')
      >>> f.write(source)
      >>> f.close  
主站蜘蛛池模板: 嵊州市| 礼泉县| 毕节市| 灵丘县| 民勤县| 略阳县| 保靖县| 彰化县| 灵璧县| 榆林市| 长葛市| 景东| 滕州市| 东光县| 黔西县| 开鲁县| 新津县| 土默特右旗| 榆林市| 瑞安市| 库车县| 永新县| 永济市| 扶沟县| 云梦县| 郧西县| 邵阳县| 汶川县| 平罗县| 丰原市| 怀集县| 丁青县| 延川县| 韩城市| 保康县| 黄浦区| 睢宁县| 鹰潭市| 建平县| 兴义市| 泉州市|