Also Requests has taken over what urllib dos in a better way,i have not used urllib in many year,other than sometime help on forum users that use urllib.
Also loop over online
Also loop over online
.txt
like this,you may get new line in wrong place.import requests fhand = requests.get('https://www.py4e.com/code/romeo.txt') for line in fhand: print(line.decode().strip())
Output:But soft what light through yonder window breaks
It is the east and Juliet is the sun
Arise fair sun and kill the envious moon
W
ho is already sick and pale with grief
Just do this.import requests fhand = requests.get('https://www.py4e.com/code/romeo.txt') print(fhand.text.strip())
Output:But soft what light through yonder window breaks
It is the east and Juliet is the sun
Arise fair sun and kill the envious moon
Who is already sick and pale with grief