Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a problem with re-saving html code. Lets create html file:

 Column@{"Plot", Plot[Sin@x, {x, 0, Pi}, ImageSize -> 200]}

Now, I want to import this file, for example to change some links inside. How to re-export this modyfied code into html in the simplest way? My way is a walkaround but it works:

Export["test.txt", Import["test.html", "Source"]]
(*lets skip modification part*)
RenameFile["test.txt", "test.html"]

I do not know html almost at all so I will be grateful for some help.

This question is related to "How to save a web page..." wich is also worth looking at.

share|improve this question
up vote 3 down vote accepted

How about something like this:

h  = Import["/tmp/htmlsource.html", "Text"];

   a : "<a href=\"" ~~ href : Shortest[__] ~~ z : "\"" :> 
   StringJoin[a, ToUpperCase[href], z]], "Text"]

This StringReplace expression changes all links inside <a href tags to upper-case, thus rendering the page completely useless... :).

share|improve this answer
Thanks, good to know. This is more elegant and faster. I'll accept this if there isn't any answer of form Export["file.html", %, "SuperOption"] :) this evening. – Kuba Jun 4 '13 at 12:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.