[英]nested selector failed in using simple html dom parser
我想獲取鏈接並抓取其內容,但我無法到達那里。 我的嵌套選擇器有什么問題?
我的 php
$dom = file_get_html('http://mojim.com/%E5%BF%83%E8%B7%B3.html?t3');
$tables = $dom->find('.iB');
$firstRow = $tables->find('tr',1)->find('td',4);
foreach ($firstRow as $value) {
echo $value;
}
?>
這是 DOM 的樣子
您只是在指向/遍歷正確元素時遇到問題。
例子:
$dom = file_get_html('http://mojim.com/%E5%BF%83%E8%B7%B3.html?t3');
$firstRow = $dom->find('table.iB', 0)->find('tr', 1)->find('td', 3);
$link = $firstRow->find('a', 0);
echo $link->href . '<br/>' . $link->title;
應該輸出:
/twy100015x34x8.htm
心跳 歌詞 王力宏
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.