【发布时间】:2014-11-01 06:10:15
【问题描述】:
我有一个包含以下代码的 html 页面。现在我只想在本地页面中以 json 格式打印名称和位置。
<div class='post-header'>
<div class='post-header-line-1'></div>
</div>
<div class='post-body entry-content' id='post-body-210098160524748093' itemprop='articleBody'>
<div class="separator" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em; text-align: center;">
<br /></div>
<br />
<br />
<ul>
<li>Name<br />Location</li>
<li>Name<br />location</li>
<li>name<br />location</li>
<li>name<br />location</li>
</ul>
<br />
输出应该是这样的,任何建议都会有所帮助。
{
"contacts": [
{
"id": "1",
"name": "Name",
"location":"location"
},
{
"id": "2",
"name": "Name",
"location":"location"
}
]
}
【问题讨论】:
-
通过 curl 加载页面,然后使用 DOMDocument,然后将节点值收集到一个数组中,最后使用 json 编码
标签: php html json curl web-scraping