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

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  
主站蜘蛛池模板: 罗甸县| 乐清市| 贵港市| 宜章县| 静海县| 奈曼旗| 洛阳市| 杂多县| 旌德县| 曲水县| 连山| 武宁县| 玉溪市| 交口县| 乐山市| 武隆县| 贡嘎县| 泰宁县| 高淳县| 鹿泉市| 吐鲁番市| 安龙县| 潮州市| 庆云县| 东丰县| 丰台区| 绥德县| 威信县| 砀山县| 泸州市| 兴和县| 安阳市| 高雄市| 南乐县| 荔浦县| 黄平县| 阳泉市| 秭归县| 封丘县| 万全县| 镇安县|