# Compile string cases into list

I have a html formatted string:

s = "<span class=\"ads__unit__content__details\"> <span>Data I want to extract</span> </span> <p class=\"ads__unit__content__keys\"> \
<span>More data I want to extract</span> <span>Even more data I want to extract</span> </p> <p>"


I am trying to extract the different parts using a string pattern:

StringCases[s, "<span>"~~x__~~"</span>"-> x]


But this somehow just works on the outermost tag pairs. This is the resulting output:

    {"<span>Data I want to extract</span> </span> <p \class=\"ads__unit__content__keys\"> <span>More data I want to \
extract</span> <span>Even more data I want to extract</span>"}


Why does it ignore the

</span>


tags in the middle of the string? I would expect a list with all the substrings separated..

• How about ImportString[s, "HTML"]? – Sjoerd Smit Sep 20 '19 at 14:25
• I have tried that @sjoerd-smit, but it gives me an error saying that the requested webpage needs javascript to function. Although I must admit it is weird because the string is displayed properly before trying to re-import it with ImportString.. – Christian Erichsen Sep 20 '19 at 21:08

StringCases[s, "<span>" ~~ Shortest[x___] ~~ "</span>" -> x]