Reputation: 509
I have a problem with read from an external html source All I want is to read an custom object in my case 'HSDPA 2100' But my actual code is read all nfo class from external source.
Piece of External html:
<table cellspacing="0">
<tbody><tr>
<th rowspan="8" scope="row">General</th>
<td class="ttl"><a href="network-bands.php3">2G Network</a></td>
<td class="nfo">CDMA 800 / 1900 </td>
</tr><tr>
<td class="ttl"> </td>
<td class="nfo">GSM 850 / 900 / 1800 / 1900 </td>
</tr>
<tr>
<td class="ttl"><a href="network-bands.php3">3G Network</a></td>
<td class="nfo">HSDPA 2100 </td>
</tr>
<tr>
<td class="ttl"> </td>
<td class="nfo">CDMA2000 1xEV-DO </td>
</tr>
<tr>
<td class="ttl"><a href="network-bands.php3">4G Network</a></td>
<td class="nfo">LTE 800 </td>
</tr>
<tr>
<td class="ttl"><a href="glossary.php3?term=sim">SIM</a></td>
<td class="nfo">Mini-SIM</td>
</tr><tr>
<td class="ttl"><a href="#" onclick="helpW('h_year.htm');">Announced</a></td>
<td class="nfo">2013, January</td>
</tr>
<tr>
<td class="ttl"><a href="#" onclick="helpW('h_status.htm');">Status</a></td>
<td class="nfo">Coming soon. Exp. release 2013, February</td>
</tr>
</tbody></table><table cellspacing="0">
<tbody><tr>
<th rowspan="2" scope="row">Body</th>
<td class="ttl"><a href="#" onclick="helpW('h_dimens.htm');">Dimensions</a></td>
<td class="nfo">-</td>
</tr><tr>
<td class="ttl"><a href="#" onclick="helpW('h_weight.htm');">Weight</a></td>
<td class="nfo"> </td>
</tr>
</tbody></table><table cellspacing="0">
<tbody><tr>
<th rowspan="4" scope="row">Display</th>
<td class="ttl"><a href="glossary.php3?term=display-type">Type</a></td>
<td class="nfo">TFT capacitive touchscreen, 16M colors</td>
</tr><tr>
<td class="ttl"><a href="#" onclick="helpW('h_dsize.htm');">Size</a></td>
<td class="nfo">1080 x 1920 pixels, 5.9 inches (~373 ppi pixel density)</td>
</tr>
<tr>
<td class="ttl"><a href="glossary.php3?term=multitouch">Multitouch</a></td>
<td class="nfo">Yes</td>
</tr>
<tr><td class="ttl"> </td><td class="nfo">- Flux UX UI</td>
I am trying using this code:
<?php
include_once('/simple_html_dom.php');
$dom = file_get_html("http://www.site.com/pantech_vega_no_6-5268.php");
// alternatively use str_get_html($html) if you have the html string already...
foreach ($dom->find('td[class=nfo]') as $node)
{
$result = $node->innertext;
$price = explode(",", $result);
echo $price[0];
}
?>
And I'm receiving this: CDMA 800 / 1900 GSM 850 / 900 / 1800 / 1900 HSDPA 2100 CDMA2000 1xEV-DO LTE 800 Mini-SIM2013Coming soon. Exp. r... etc
Wat i want is HSDPA 2100
but for other models of phones value could be HSDPA 1900
or other and HSPDA
will always be stable and first.
Upvotes: 2
Views: 149
Reputation:
All td have the same class name "nfo" and you loop through all elements so the result you get is as expected.
If the data you want is always located at the third row you can populate an array instead of getting a variable and then get the third value. Like this $result[2]
UPDATED: If HSDPA is always there just check for it.
<?php
include_once('/simple_html_dom.php');
$dom = file_get_html("http://www.site.com/pantech_vega_no_6-5268.php");
// alternatively use str_get_html($html) if you have the html string already...
foreach ($dom->find('td[class=nfo]') as $node)
{
$result = $node->innertext;
if (strpos($result, 'HSDPA') === false)
{
continue;
}
$price = explode(",", $result);
echo $price[0];
break;
}
?>
Upvotes: 1