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 .

4

1 回答 1

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

它也替换了包含的路径。

于 2013-07-21T11:56:08.693 回答