(Mar-07-2019, 11:22 PM)Truman Wrote: Yes, this works.
That's different is a file path in you other post it's a url.
Then need a web package as mention bye @
ichabod801,then it's of course Requests you should use.
import requests
import os
url = 'http://pythonscraping.com/files/inaugurationSpeech.txt'
file_name = os.path.basename(url)
response = requests.get(url)
with open(file_name,'wb') as f:
f.write(response.content)
Do not use
encoding='latin-1'
the rule is simple do text show without any problem in Python 3.
Then take it out/in with
encoding='utf-8'
.
Taking data into Python 3 may sometime require other encoding that utf-8.
s = 'Crème and Spicy jalapeño ☂ ⛄日本語のキ'
# Out
with open('unicode.txt', 'w', encoding='utf-8') as f_out:
f_out.write(s)
# Back in
with open('unicode.txt', encoding='utf8') as f:
data = f.read()
print(data)
Output:
Crème and Spicy jalapeño ☂ ⛄日本語の