#!user/bin/python 3.5.2
#-*- encoding=utf-8   -*-
import requests
import os

url=input('please input a url:')
print ('hold on several seconds')
if url[0:4]!="http":
    url='http://'+url
kv={'user-agent':'Mozilla/5.0'}
r=requests.get(url,headers =kv)
r.raise_for_status()
r.encoding=r.apparent_encoding
ans=input('save the webpage?(y or n)')
if ans=='y':
    root=input('please input a path to save the webpage:')
    path=root+url.split('/')[-1]+'.html'
    if not os.path.exists(root):
        os.mkdir(root)
    if not os.path.exists(path):
        with open(path,'wb') as f:
            f.write(r.content)
            f.close()
            print('success!')
    else:
        print('the file has existed')