【发布时间】:2013-04-16 06:56:51
【问题描述】:
我有这段代码用于从表中抓取团队名称
$url = 'http://fantasy.premierleague.com/my-leagues/303/standings/';
$html = @file_get_html($url);
//Cut out the table
$FullTable = $html->find('table[class=ismStandingsTable]',0);
//get the text from the 3rd cell in the row
$teamname = $FullTable->find('td',2)->innertext;
echo $teamname;
这很有效......并给出了这个输出......
<a href="/entry/110291/event-history/33/">Why Always Me?</a>
但是当我添加这些行时..
$teamdetails = $teamname->find('a')->href;
echo $teamdetails;
我得到完全空白的输出。
知道为什么吗?我试图将/entry/110291/event-history/33/ 作为一个变量,将Why Always Me? 作为另一个变量。
【问题讨论】:
-
您检查了
$teamdetails吗?当您分配$FullTable->find('td',2)->innertext的值时,它可能不再是一个对象,而是一个简单的字符串。在这种情况下,你应该做一个 preg_match 来提取你的href。还有什么包含$teamname.? -
谢谢.. 我刚刚得到这个工作。我不完全确定为什么,但我无法 -> 在 $teamname 中找到东西,所以我只是做了
$teamname = $FullTable->find('td',2)->find('a',0)->href;和$teamname = $FullTable->find('td',2)->find('a',0)->innertext;,它给出了我需要的值。 -
Enable PHP error logging。当你得到一个空白页时,错误日志就会包含原因。
-
@M8R-1jmw5r 谢谢 - 我会看看
标签: php simple-html-dom