()
| 6 | import urllib.request # instead of urllib2 like in Python 2.7 |
| 7 | |
| 8 | def main(): |
| 9 | # open a connection to a URL using urllib2 |
| 10 | webUrl = urllib.request.urlopen("http://www.google.com") |
| 11 | |
| 12 | # get the result code and print it |
| 13 | print ("result code: ", webUrl.getcode()) |
| 14 | |
| 15 | # read the data from the URL and print it |
| 16 | data = webUrl.read() |
| 17 | print (data) |
| 18 | |
| 19 | if __name__ == "__main__": |
| 20 | main() |