Python Penetration Testing Cookbook
上QQ阅读APP看书,第一时间看更新

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