no scheme in url fix
This commit is contained in:
parent
5b05f3e8d0
commit
2666d7911a
16
nevernote.py
16
nevernote.py
@ -17,7 +17,7 @@ def download_content(url):
|
|||||||
'''download page and decode it to utf-8'''
|
'''download page and decode it to utf-8'''
|
||||||
up = urlparse(url)
|
up = urlparse(url)
|
||||||
if not up.scheme:
|
if not up.scheme:
|
||||||
up = urlparse('http://' + url)
|
up = urlparse('//' + url)
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"Host": up.netloc,
|
"Host": up.netloc,
|
||||||
@ -25,7 +25,7 @@ def download_content(url):
|
|||||||
"Connection": "keep-alive",
|
"Connection": "keep-alive",
|
||||||
}
|
}
|
||||||
|
|
||||||
if up.scheme == 'http':
|
if not up.scheme or up.scheme == 'http':
|
||||||
conn = http.client.HTTPConnection(up.netloc)
|
conn = http.client.HTTPConnection(up.netloc)
|
||||||
elif up.scheme == 'https':
|
elif up.scheme == 'https':
|
||||||
conn = http.client.HTTPSConnection(up.netloc)
|
conn = http.client.HTTPSConnection(up.netloc)
|
||||||
@ -36,8 +36,8 @@ def download_content(url):
|
|||||||
response = conn.getresponse()
|
response = conn.getresponse()
|
||||||
|
|
||||||
# follow redirects
|
# follow redirects
|
||||||
if (response.status == http.client.MOVED_PERMANENTLY) \
|
if ((response.status == http.client.MOVED_PERMANENTLY)
|
||||||
or (response.status == http.client.FOUND):
|
or (response.status == http.client.FOUND)):
|
||||||
new_url = response.getheader('Location')
|
new_url = response.getheader('Location')
|
||||||
print('Redirect to ' + new_url)
|
print('Redirect to ' + new_url)
|
||||||
return download_content(new_url)
|
return download_content(new_url)
|
||||||
@ -73,10 +73,10 @@ def write_file(page):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description=
|
parser = argparse.ArgumentParser(
|
||||||
'Nevernote - download pages locally.')
|
description='Nevernote - download pages locally.')
|
||||||
parser.add_argument('urls', metavar='URL', type=str, nargs='+', help=
|
parser.add_argument('urls', metavar='URL', type=str, nargs='+',
|
||||||
'URL of page to download')
|
help='URL of page to download')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user