簡體   English   中英

嵌套選擇器無法使用簡單的 html dom 解析器

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM