I´ve to parse a HTML site presenting a call list. After converting to XML the structur is:
<body>
<form name="mainform" method="POST" action="baz" class="all">
<input type="submit" value="" style="position:absolute;top:-9999px;left:-9999px;" name="apply"/>
<p>foo</p>
<div class="bar">
..
</div>
<br/>
<div class="onPageTabsBox">
<ul class="tabs onPageTabs">
...
</ul>
</div>
<table id="baz">
<tr class="thead">
...
</tr>
</table>
<div id="uiScroll">
<table id="bla">
<tr class="showif_in">
...
</tr>
...
<tr class="showif_out">
<td class="call_out" title="outbound call" datalabel="29.12.19 11:13"/>
<td>29.12.19 11:13</td>
<td title="Doe, John (privat) = 0123456789" datalabel="Name / Rufnummer">
<a href=" " onclick="return onDial('0123456789');">Doe, John (privat)</a>
</td>
<td datalabel="foo">bar</td>
<td title="987654 (Internet)" datalabel="own number">987654</td>
<td class="duration" data-timestr="0:02" datalabel="duration">2 Min</td>
<td class="btncolumn">
...
</td>
</tr>
<tr class="showif_out">
...
</tr>
Function I need is to get phone numbers from incoming, outgoing, ... calls.
So I try to get the phone number(s) from that td
node, where title
contains " = "
The function is at present like this:
function getCallList($config, string $type = '')
{
...
$xmlSite = convertHTMLtoXML($response);
switch ($type) {
case 'in':
case 'out':
case 'fail':
case 'rejected':
$query = sprintf('//form/div/table/tr[@class="showif_%s"]', $type);
break;
default: // get all recorded calls
$query = '//form/div/table/tr';
}
$rows = $xmlSite->xpath($query);
foreach ($rows as $row) {
$numbers = $row->xpath('substring-after(//td[@title], " = ")');
}
...
}
After consulting similar questions here I tried $numbers = $row->evaluate('substring-after(//td[@title], " = ")');
and several other xPath expressions - unfortunately I can't get the substring. Apart from that, I suspect that it should also be possible to get an array with the phone numbers with just one query.