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

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  
主站蜘蛛池模板: 延边| 北流市| 岳阳市| 龙岩市| 沙雅县| 台北县| 莱西市| 勐海县| 平泉县| 镇江市| 县级市| 西贡区| 绥化市| 淮滨县| 铜梁县| 长宁县| 边坝县| 安西县| 哈巴河县| 石景山区| 瑞金市| 澄江县| 沙坪坝区| 兰溪市| 巨鹿县| 拉孜县| 自贡市| 柘城县| 吐鲁番市| 巫山县| 通榆县| 民勤县| 望城县| 磴口县| 曲靖市| 广元市| 乌拉特中旗| 成安县| 双牌县| 巩留县| 芜湖市|