【发布时间】:2023-03-15 12:53:01
【问题描述】:
我一直在使用 PHP Simple HTML DOM Parser Manual 发现这里 http://simplehtmldom.sourceforge.net/manual.htm 并且我在一些测试中取得了成功,除了这个:
它有嵌套的表和跨度,我想用 mynum 类解析跨度的外部文本。
<?php
require_once 'simple_html_dom.php';
$url = 'http://relumastudio.com/test/target.html';
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21");
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
$DEBUG = 1;
if($DEBUG){
$html = new simple_html_dom();
$html->load($url);
echo $html->find('span[class=mynum]',0)->outertext; // I should get 123456
}else{
echo $result;
}
curl_close($ch);
我以为我只需拨打一次电话echo $html->find('span[class=mynum]',0)->outertext; 即可获得短信123456,但我做不到。
有什么想法吗?任何帮助是极大的赞赏。谢谢。
【问题讨论】:
-
您应该发布带有您的问题的 html,而不是 curl 代码。
标签: php html simple-html-dom