我看到這是可能的使用jQuery,但如何在QueryPath中完成?是否可以使用QueryPath選擇HTML註釋?
Selecting HTML Comments with jQuery
如果沒有,任何人都可以提出一個HTML解析器,可以選擇評論?
我看到這是可能的使用jQuery,但如何在QueryPath中完成?是否可以使用QueryPath選擇HTML註釋?
Selecting HTML Comments with jQuery
如果沒有,任何人都可以提出一個HTML解析器,可以選擇評論?
QueryPath附帶一個名爲QPXML
的擴展,它具有多種附加方法。其中之一是comment()
。
要使用它,只需將其包含在你的腳本:
include 'QueryPath/QueryPath.php';
include 'QueryPath/Extensions/QPXML.php';
htmlqp($html, $selector)->comment();
這將檢索附加到當前選擇的節點(或多個)第一條評論。
如果你有一個非常複雜的一套都是一樣的節點中的註釋,你可以做這樣的事情:
$nodes = $qp->get();
foreach ($nodes as $node) {
foreach ($node->childNodes as $child) {
if ($child->nodeType == XML_COMMENT_NODE) {
// $child is a comment.
print $child->textContent;
}
}
}
這是有點難看,但它給其中一個元素都有的情況下更好地進入很多意見在裏面。
要通過的QueryPath獲得HTML頁面的所有評論:
function getAllComments($node) {
if ($node->hasChildNodes()) {
foreach ($node->childNodes as $child) {
$this->getAllComments($child);
if ($child->nodeType == XML_COMMENT_NODE) {
echo $child->textContent;
}
}
}
}
$html = $qp->get() ;
getAllComments($html[0]);
謝謝!當我需要時,我應該在QP郵件列表上提問,幸運的是我找到了解決方法。 :) –
我必須做'\ QueryPath :: enable('\ QueryPath \ Extension \ QPXML');'讓QPXML工作。 –