-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterenetWebPage.py
More file actions
37 lines (28 loc) · 894 Bytes
/
Copy pathInterenetWebPage.py
File metadata and controls
37 lines (28 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#
# Example file for retrieving data from the internet
# LinkedIn Learning Python course by Joe Marini
#
# import data from a web server
import urllib.request
import urllib.error
def webpage(url):
try:
weburl = urllib.request.urlopen(url)
# Chat GPT error handler!
except urllib.error.URLError as e:
if hasattr(e, 'reason'):
print('ERROR: Cannot reach the server.')
print('Reason: ', e.reason)
elif hasattr(e, 'code'):
print('ERROR: Server cannot fulfill this request.')
print('Error code: ', e.code)
else:
# everything is fine
print("Result Code:", weburl.getcode())
data = weburl.read()
print(data)
def main():
webpage("https://www.linkedin.com/in/dave-dempski")
webpage("http://www.google.com")
if __name__ == "__main__":
main()