tabebqena
tabebqena

Reputation: 1260

How to convert html links?

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 .

Upvotes: 1

Views: 143

Answers (1)

tobspr
tobspr

Reputation: 8376

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

It replaces also the path of includes.

Upvotes: 1

Related Questions