I’m trying to extract the second link under the description tag. I have written the following code, but it looks really messy with freads and substrings (just to get it to work). Is there any cleaner way to accomplish this?

magic(Url)->
Tag = “.xml”,
inets:start(),
{ ok, {Status, Headers, Body }} = httpc:request(Url ++ Tag),
{ Xml, Rest } = xmerl_scan:string(Body),
{xmlObj , string , A } = xmerl_xpath:string(“substring-after(substring-after(substring->before(//channel/item/description[1], ‘\”>[link]’) , ‘br’) , ‘href=’)”, Xml),
{ok,_,B} = io_lib:fread(“~6s” , A),
string:sub_string(B,1,string:len(B)-1).
Not a perfect solution, but you may use such xpaths
//channel/item/description[1]/text()[16]and//channel/item/description[1]/text()[24]extracted strings contains urls + quotes at the beginning, so you may use list matching syntax to cut off quotation marks:
[_|Url] = ...So use this:
[{_,_,_,_,[_|U1],_}] = xmerl_xpath:string("//channel/item/description[1]/text()[16]", Xml).to bind U1 with first url.Test in shell: