我的任务是从HTML中提取数据,我需要为HTML中的每组p标签获取数据数组。下面是一个示例。
<p class="ft01" style="margin: 0; padding: 0; font-size: 16px; font-family: Times; color: #000000; position: absolute; top: 103px; left: 63px; white-space: nowrap;">Title </p>
<p class="ft01" style="margin: 0; padding: 0; font-size: 16px; font-family: Times; color: #000000; position: absolute; top: 103px; left: 349px; white-space: nowrap;">1234 </p>
<p class="ft01" style="margin: 0; padding: 0; font-size: 16px; font-family: Times; color: #000000; position: absolute; top: 103px; left: 461px; white-space: nowrap;">$30 </p>
<p class="ft01" style="margin: 0; padding: 0; font-size: 16px; font-family: Times; color: #000000; position: absolute; top: 103px; left: 563px; white-space: nowrap;">$10,000,000 </p>
<p class="ft01" style="margin: 0; padding: 0; font-size: 16px; font-family: Times; color: #000000; position: absolute; top: 103px; left: 777px; white-space: nowrap;">3,000,000 </p>
此 HTML 将重复多次,使“标题”和“1234”标签保持不变,然后在某个点切换到不同的标签。“顶部”和“左侧”值将在整个 HTML 中不断变化。我有能力循环访问现有的“Title”和“1234”标签,以匹配这部分内容。
$title_label = 'Title';
$number_label = '1234';
preg_match_all('%\d{2}px; white-space: nowrap;">$title_label </p>%', $html_content, $array_match);
$array_cost_name = $array_match[1];
$array_return_name = $array_match[2];
$array_number_name = $array_match[3];
然后,我需要 3 个数组来包含最后 3 个标签字段。对于提供的示例 HTML,我希望“$30”、“$10,000,000”和“3,000,000”是每个数组的第一个值。
我不知道如何编写正则表达式来处理这种情况。任何人都可以帮忙吗?
冉冉说
森林海
守候你守候我
喵喔喔
随时随地看视频慕课网APP