将HTML解析为JSON
我的任务是使用Yahoo管道获取所有的数据并将它们放入JSON提要中。我不完全确定如何获得每个更新,因为它们不是单独的元素,而是标题等的集合。任何共享的智慧都将不胜感激将HTML解析为JSON,html,xml,json,dom,yahoo-pipes,Html,Xml,Json,Dom,Yahoo Pipes,我的任务是使用Yahoo管道获取所有的数据并将它们放入JSON提要中。我不完全确定如何获得每个更新,因为它们不是单独的元素,而是标题等的集合。任何共享的智慧都将不胜感激 SMS更新 <h1 id="blogtitle">SMS Update</h1> <div class="blogposttime blogdetail">Left at 2nd January 2010 at 01:12</div> <div class="blogca
SMS更新
<h1 id="blogtitle">SMS Update</h1>
<div class="blogposttime blogdetail">Left at 2nd January 2010 at 01:12</div>
<div class="blogcategories blogdetail">Recieved by SMS (Location: Pokhara - Nepal)</div>
<p class="blogpostmessage">
RACE DAY! We took the extra day off to pimp the rick some more, including a huge Australian flag. Quiet night at a pub with 6 other teams. Time for brekkie and then we're off to the rickshaw grounds for 8:30 for 10am start.
</p>
2010年1月2日01:12左
通过短信接收(地点:尼泊尔博卡拉)
对于DOM/XML解析器来说,这似乎是一项相当简单的工作
由于块没有包含在XML标记中,因此可以查找每个块中存在的元素,例如SMS更新
定义了新块的开始
使用DOM解析器查找id为blogtitle的所有元素。此时,您可以使用DOM函数来引用blogtitle元素的nextSibling。您所需要的只是blogtitle元素后面的3同级
只需做一点工作,您就可以轻松地使用此逻辑构建JSON对象。谢谢,但我通过查找页面上的所有blogtitle元素以及posttime等“解决”了这一问题,并使用Nokogiri(Ruby)对其进行迭代,因为它们的顺序总是正确的。似乎工作得很顺利。不过,谢谢你的回答。