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

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  
主站蜘蛛池模板: 阳曲县| 眉山市| 原平市| 关岭| 兴安县| 濮阳市| 甘孜县| 循化| 萨嘎县| 剑河县| 增城市| 乌审旗| 福泉市| 虹口区| 晋江市| 彭水| 都江堰市| 马山县| 额尔古纳市| 甘肃省| 夏邑县| 会东县| 额济纳旗| 鲁甸县| 昌平区| 桦川县| 民权县| 岑溪市| 拉孜县| 江华| 乐业县| 安顺市| 琼中| 玉龙| 西昌市| 文昌市| 香格里拉县| 乌鲁木齐县| 酉阳| 澄城县| 昭觉县|