title: how to change links of html file to local links
body: <p>I'm making my own web crawler on python 2.7   that download a website to a path in my computer and I save the files in similar way they are saved on the folder of the site on the server for example:</p>
  
  <p><a href="https://stackoverflow.com/questions/ask?title=python+how+to+change+links+of+html+file+to+local+links">https://stackoverflow.com/questions/ask?title=python+how+to+change+links+of+html+file+to+local+links</a></p>
  
  <p>I will make a directory of stackoverflow inside it a directory of questions and inside it the html file of this page...</p>
  
  <p>How I can change the links to the pages in the internet to link to pages I downloaded if they already exist on my computer?</p>
  
  <p>For example if there is :
  <code>&lt;a href="https://stackoverflow.com/questions"&gt;</code> so I will change this html code through python to
  <code>&lt;a href="/questions"&gt;</code> or something like this..</p>
  
  <p>I don't know if it helps but this is the function I use to download on a single file:
   def downloadFile(path , url):</p>
  
  <pre><code>try :
      print "Downloading  : " + url
      path=path + urlparse(url).path 
      path , fileName = pathNameSplit(path)
  
  
      make_sure_path_exists(path)
  
  
  
      print "trying to downoad " + fileName 
      if (fileName.count(".") == 0 ):fileName = fileName + ".html"
      #pickle.dump( url2Html(url) , open( path + fileName, "w" ))
  
      urllib.urlretrieve(url, path + fileName)
      print "Download of  " + url + " Completed"
  except Exception:
      print "Sometihng occured in the download of " + url
  </code></pre>