Skip to content

Commit 9f9c05c

Browse files
chg: use python requests for fetching to fix #17
1 parent b52c02b commit 9f9c05c

File tree

2 files changed

+4
-11
lines changed

2 files changed

+4
-11
lines changed

scripts/inscript.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@
1717
__email__ = "[email protected]"
1818
__status__ = "Prototype"
1919

20-
try:
21-
from urllib.request import urlopen
22-
except ImportError:
23-
from urllib import urlopen
24-
from io import open
20+
import requests
2521
import argparse
2622
import sys
2723
from os.path import isfile
@@ -51,11 +47,7 @@ def get_parser():
5147
with open(args.input, encoding=args.encoding, errors='ignore') as f:
5248
html_content = f.read()
5349
elif args.input.startswith("http://") or args.input.startswith("https://"):
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)
50+
html_content = requests.get(args.input).text
5951
else:
6052
print("ERROR: Cannot open input file '{}'.\n".format(args.input))
6153
parser.print_help()

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737

3838
# Requirements
3939
install_requires=[
40-
'lxml'
40+
'lxml',
41+
'requests'
4142
]
4243

4344
)

0 commit comments

Comments
 (0)