Skip to content

Commit a1ef7c8

Browse files
fix: user server content type, if available (fixes #16)
* use content type returned by server, if available.
1 parent 502ffea commit a1ef7c8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

scripts/inscript.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ def get_parser():
5151
with open(args.input, encoding=args.encoding, errors='ignore') as f:
5252
html_content = f.read()
5353
elif args.input.startswith("http://") or args.input.startswith("https://"):
54-
html_content = urlopen(args.input).read().decode(args.encoding)
54+
http_client = urlopen(args.input)
55+
if ('Content-Type' in http_client.headers and
56+
'charset=' in http_client.headers['Content-Type']):
57+
args.encoding = http_client.headers['Content-Type'].split('charset=')[1]
58+
html_content = http_client.read().decode(args.encoding)
5559
else:
5660
print("ERROR: Cannot open input file '{}'.\n".format(args.input))
5761
parser.print_help()

0 commit comments

Comments
 (0)