Php 从XPath中删除特定表
我有这段代码,并用DOMXPath删除了一个给定的tdPhp 从XPath中删除特定表,php,dom,xpath,Php,Dom,Xpath,我有这段代码,并用DOMXPath删除了一个给定的td $html = file_get_contents('WebProxy.html'); $xml = new DOMDocument(); $xml->validateOnParse = true; @$xml->loadHTML($html); $xpath = new DOMXPath($xml); $table =$xpath->query("//*[@id='proxylisttable']")->item
$html = file_get_contents('WebProxy.html');
$xml = new DOMDocument();
$xml->validateOnParse = true;
@$xml->loadHTML($html);
$xpath = new DOMXPath($xml);
$table =$xpath->query("//*[@id='proxylisttable']")->item(0);
// for printing the whole html table just type: print $xml->saveXML($table);
$rows = $table->getElementsByTagName("tr");
foreach ($rows as $row) {
$cells = $row -> getElementsByTagName('td');
foreach ($cells as $cell) {
echo $cell->nodeValue. . '<br>';
}
}
我该怎么做呢,谢谢您的帮助也许您可以通过排除不需要的单元格来调整xpath查询 例如:
<?php
$html = file_get_contents('WebProxy.html');
$xml = new DOMDocument();
$xml->validateOnParse = true;
@$xml->loadHTML($html);
$xpath = new DOMXPath($xml);
$cells =$xpath->query("//*[@id='proxylisttable']/tr/td[position() != 3 and position() != 6 and position() != 7 and position() != 8]");
foreach ($cells as $cell) {
echo $cell->nodeValue . "<br>";
}
validateOnParse=true;
@$xml->loadHTML($html);
$xpath=newdomxpath($xml);
$cells=$xpath->query(“/*[@id='proxylistable']/tr/td[position()!=3和position()!=6和position()!=7和position()!=8]”;
foreach($cells作为$cell){
echo$cell->nodeValue。“
”;
}
116.226.187.242
1080
China
Socks4
<?php
$html = file_get_contents('WebProxy.html');
$xml = new DOMDocument();
$xml->validateOnParse = true;
@$xml->loadHTML($html);
$xpath = new DOMXPath($xml);
$cells =$xpath->query("//*[@id='proxylisttable']/tr/td[position() != 3 and position() != 6 and position() != 7 and position() != 8]");
foreach ($cells as $cell) {
echo $cell->nodeValue . "<br>";
}