- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在从外部 html 源读取时遇到问题 我只想读取我的案例“HSDPA 2100”中的自定义对象但我的实际代码是从外部源读取所有 nfo 类。
一段外部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>
我正在尝试使用这段代码:
<?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];
}
?>
我收到了:CDMA 800/1900 GSM 850/900/1800/1900 HSDPA 2100 CDMA2000 1xEV-DO LTE 800 Mini-SIM2013即将推出。 Exp。 r...等
我想要的是 HSDPA 2100
但对于其他型号的手机,值可以是 HSDPA 1900
或其他并且 HSPDA
将始终稳定且首先。
最佳答案
所有 td 都具有相同的类名“nfo”,您循环遍历所有元素,因此获得的结果符合预期。
如果你想要的数据总是位于第三行,你可以填充一个数组而不是获取一个变量,然后获取第三个值。像这样 $result[2]
更新:如果 HSDPA 始终存在,只需检查一下即可。
<?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;
}
?>
关于php - 从外部 html 源自定义对象读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14571961/
我正在使用第三方 JS 库。它需要一些 RegExp 作为输入,用于匹配字符串的各个部分。现在我需要在我传递的RegExp中使用lookbehind,但是lookbehind在JS RegExp中没有
我正在尝试创建一个包含几个下拉菜单的表单。第一个由“客户名称”填充,该名称是从我的 MYSQL 数据库中提取的。选择后,其下方的下拉菜单将填充到数据库中与该“客户名称”关联的可用“客户站点”(在表中的
我运行一个包含数千个容器的 docker 集群,每天随机运行几次我有一个进程“卡住”阻止容器停止。下面是一个带有相应进程的示例容器,以及我试图杀死容器/进程的所有内容。 容器: # docker ps
抱歉,这是一个很长的问题,但它有点复杂。感谢阅读。 我有一个我开发的自定义套接字工厂和套接字类 (Android 5.0),用于执行我需要在该级别执行的一些特定任务。这是我的套接字工厂和套接字(为简洁
有这样的事情: var _ = require("sdk/l10n").get; console.log(_("hello_id!")); 对于新的 SDK。 如何使用它来收集 Firefox ENT
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 3 年前。 Improv
我在我的 PHP 应用程序中实现了一个亵渎过滤器,它根据存储在 MySQL 中的表的亵渎单词列表检查用户从浏览器客户端发送的字符串。该表如下所示: Word badWord1 badWord2 etc
ASP.net 给出了这个奇怪的错误信息。它在尝试加载使用名为“loggedin.master”的母版页的页面时出现。 完整的错误信息如下: [A]ASP.loggedin_master cannot
我正在尝试在 iOS 应用程序和 java servlet 之间实现 AES 加密。 Java servlet 使用 BouncyCaSTLe 库,而 iOS 应用程序使用 OpenSSL。尽管我在双
我是一名优秀的程序员,十分优秀!