【发布时间】:2023-03-22 05:47:01
【问题描述】:
我需要将此 HTML 代码解析为字符串数组,然后我可以将其添加到数据库中。这是我正在解析的 HTML 代码:
http://gyazo.com/eab3a140264d354060268a97ae8fa6de
顶部的“market_listing_table_header”类似乎定义了页面其余部分将显示的内容。 “market_listing_row_link”类是 100 个中的 1 个,但我还得到了 40 个 100 个列表。
我需要的是“沙漠之鹰纪念品 | 手炮(磨损严重)”部分中的每个类别,它位于“market_listing_item_name_block”中。 “result_0_name”从那个到“result_100_name”然后再次从 0 开始,用于页面上的 ~4000 个列表。
如果可能的话,我还想在“result_0_image”部分中获取 src="get this link" 以与“result_0_name”一起使用。
这是我现在使用的代码:
$str = '$html';
$DOM = new DOMDocument;
$DOM->loadHTML($str);
$items = $DOM->getElementsByTagName('market_listing_item_block');
//just displaying the items for now, for testing,
//though I may need help putting the data in an array as well.
for ($i = 0; $i < $items->length; $i++)
echo $items->item($i)->nodeValue . "<br/>";
我在“getElementsByTagName('???');”中添加了不同的代码部分,但我无法弄清楚获得我想要的部分应该是什么。任何帮助都会很棒,谢谢。
【问题讨论】:
标签: php mysql dom html-parsing