Dec-17-2022, 12:03 AM
Please review my code. Is this the right thing to do?
I get a HTTP date stamp from a web response, and convert it into a datetime object:
For arbitrary URLs, how do I know what datetime format string to use?
Thanks in advance.
I get a HTTP date stamp from a web response, and convert it into a datetime object:
import datetime from urllib import request URL = "https://www.unicode.org/Public/UNIDATA/Scripts.txt" response = request.urlopen(URL) s = response.getheader('DATE') obj = datetime.datetime.strptime(s, '%a, %d %b %Y %H:%M:%S %Z')This seems to work for the specific file I am trying to download. Is this the best way? (Note: for reasons, I'm limited to only using the stdlib, so no
requests
module, sorry.)For arbitrary URLs, how do I know what datetime format string to use?
Thanks in advance.