Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question on importing news headlines via a RSS feed reminded me of an old question I've been meaning to ask.

Past attempts at finding a use for Mathematica's RSS to Notebook capabilities were frustrated by the fact that images within a given post always get parsed as a long ugly link to the image, rather than importing the image itself.

Consider the following blog:

NotebookPut[Import["http://gregmankiw.blogspot.com/feeds/posts/default?alt=rss", "RSS"]];

Scrolling down to one of the posts containing an simple image (along with a tiny snipped of text that correctly hyperlinks to a WSJ article), one often sees something like:

enter image description here

Request 1: Instead of the messy html text---that is a working hyperlink to the actual image---I'd rather see an actual image.

Many posts also contain embedded video clips for sites like YouTube, etc. Instead of seeing an messy link, as in:

enter image description here

Request 2: Can you instead display a static video image (and make that image a hyperlink to the actual YouTube video---and feel free to strip out the tracking crap...)? I realize this may require some knowledge of how YouTube embedded links actually work. Dunno if it's easy, or even possible, to request a static 'placeholder' image from YouTube.

share|improve this question
add comment

1 Answer 1

As the result of the RSS is just a notebook expression, you can perform any transformation of that expression before you show the notebook. Here I replace the buttonbox as which the hyperlink is represented with a graphics cell that shows the image:

blognb = Import[
   "http://gregmankiw.blogspot.com/feeds/posts/default?alt=rss", 
   "RSS"];

blognb /. {
  ButtonBox[
    RowBox[{imgtag_ /; 
       StringMatchQ[imgtag, "<img" ~~ ___], ___}], ___] :> 
   Cell[BoxData[ToBoxes[
      Import[StringReplace[
        imgtag,
        ___ ~~ "src=\"" ~~ url : (Except["\""] ..) ~~ ___ :> url]]
      ]], "Graphics"] } // NotebookPut

I think there is also a bug in the RSS import as the string that represents the img-tag doesn't look like it was digested correctly. Of course that approach makes some assumptions on how those hyperlinks look like and might need some fine tuning depending on how much the representation of those links will vary in practice.

In a similar way you could try to handle the youtube stuff, using string functions to extract the url and then do whatever is needed to get the preview picture, if possible. That's something that I don't know how to do and think is slightly off topic for MSE, you might get that information elsewhere. With the url and the preview picture you could then create a hyperlink button showing the preview and opening the url in a similar way to what I've done for the image.

share|improve this answer
add comment

Your Answer

 
discard

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.