【发布时间】:2019-07-01 14:10:45
【问题描述】:
我正在使用 Simple HTML DOM 抓取网站,输出如下所示:
<tr>
<th>Satuan</th>
<th>Harga Barang 1</th>
<th>Harga Barang 2</th>
<th>Harga Barang 3</th>
<th>Harga Barang 4</th>
</tr>
<tr>
<td>0.5</td>
<td>Rp 388.000</td>
<td>Rp 342.000</td>
<td>Rp 456.000</td>
<td>Rp 377.000</td>
</tr>
<tr>
<td>1.0</td>
<td>Rp 725.000</td>
<td>Rp 676.000</td>
<td>Rp 855.000</td>
<td>Rp 684.000</td>
</tr>
这是我的代码:
<?php
include('simple_html_dom.php');
$html = new simple_html_dom();
$html->load_file("mylink.com/blabla");
foreach($html->find('tr') as $e) {
echo $e;
}
?>
如何将输出转换成数组?
【问题讨论】:
-
访问循环内节点的文本内容(或您真正感兴趣的任何内容),并将其简单地分配为新的数组元素 - 实际的问题在哪里? (仅供参考,您是 scraping,而不是 scraping。)
标签: php html arrays web-scraping