Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将HTML解析为JSON_Html_Xml_Json_Dom_Yahoo Pipes - Fatal编程技术网

将HTML解析为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

我的任务是使用Yahoo管道获取所有的数据并将它们放入JSON提要中。我不完全确定如何获得每个更新,因为它们不是单独的元素,而是标题等的集合。任何共享的智慧都将不胜感激

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左 通过短信接收(地点:尼泊尔博卡拉)

比赛日!我们多放了一天假去拉皮条客,包括一面巨大的澳大利亚国旗。与其他6支球队在酒吧度过一个安静的夜晚。到布雷基的时间了,然后我们去人力车场,8:30,上午10点出发。

对于DOM/XML解析器来说,这似乎是一项相当简单的工作

由于块没有包含在XML标记中,因此可以查找每个块中存在的元素,例如
SMS更新
定义了新块的开始

使用DOM解析器查找id为blogtitle的所有元素。此时,您可以使用DOM函数来引用blogtitle元素的nextSibling。您所需要的只是blogtitle元素后面的3同级

只需做一点工作,您就可以轻松地使用此逻辑构建JSON对象。

谢谢,但我通过查找页面上的所有blogtitle元素以及posttime等“解决”了这一问题,并使用Nokogiri(Ruby)对其进行迭代,因为它们的顺序总是正确的。似乎工作得很顺利。不过,谢谢你的回答。