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

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  
主站蜘蛛池模板: 东乌珠穆沁旗| 岐山县| 谢通门县| 依兰县| 昂仁县| 镇江市| 塔河县| 襄汾县| 田阳县| 东阳市| 满洲里市| 元谋县| 海安县| 遂溪县| 屏南县| 巴南区| 崇礼县| 铜鼓县| 凯里市| 江西省| 沧州市| 鄂尔多斯市| 泾川县| 林西县| 上高县| 嘉善县| 新建县| 金门县| 江西省| 大宁县| 泊头市| 芒康县| 房产| 科技| 开平市| 仲巴县| 普宁市| 东宁县| 峨山| 龙州县| 东平县|