1

suppose that I download many html pages to the directory

/path/to/my/dir

the .html pages contain links like :

"<a href="http://www.example.com/lessons/firstlesson.htm">first lesson</a>"

"<a href="http://www.example.com/lessons/secondlesson.htm">second lesson</a>"

Thanks to TobSpr , the answer convert them as follow :

"<a href="/path/to/my/dir/firstlesson.htm">first lesson</a>"

"<a href="/path/to/my/dir/secondlesson.htm">second lesson</a>"

UPDATE

but how to deal with this format of links : "first lesson"

"<a href="../index.htm">index</a>"

Using the usual string functions is very difficult , dirty and buggy , So I hope to get another beter way .

5
  • Can't you just use find/replace in Notepad++ or similar? Scripting this seems unnecessary. Commented Jul 21, 2013 at 9:24
  • doing this for many many links in each page is impossible ... Commented Jul 21, 2013 at 9:39
  • Why? Most editors have the ability to replace all instances of a string across multiple files. In fact, Notepad++ can probably do this in a more robust manner than you will with Python. Commented Jul 21, 2013 at 9:49
  • 3
    why does content.replace("http://www.example.com/", "file///path/to/dir/") not work for you? It would also replace image and include paths Commented Jul 21, 2013 at 10:42
  • @TobSpr add your comment as answer so tabebqena can mark it as accepted. Commented Jul 21, 2013 at 11:53

1 Answer 1

1
content.replace("http://www.example.com/", "file///path/to/dir/")

It replaces also the path of includes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.