单击A.html中的链接时:
<tr>
<td class="book"><a class="booklink" ref="../collection?file=book1.pdf">
Good Read
</a>
-Blah blah blah
</td>
</tr>将?file=book1.pdf传递给B.html:
<?php
$src = $_GET['file'];
?>
<iframe src="<?php echo $src; ?>" >
</iframe>问:-如何使用简单的html dom从A.html中检索文本"Good Read-Blah blah“并将其粘贴到B.html的元描述中?(请注意,A.html中的表中有数千个列出的数据)
谢谢。
发布于 2013-08-10 09:37:50
对load your HTML document和XPath to search it使用DOM。
// note: if the HTML to parse has bad syntax, use: libxml_use_internal_errors(true);
$doc = new DOMDocument;
$doc->loadHTML(file_get_contents('A.html'));
if ($doc === false) {
throw new RuntimeException('Could not load HTML');
}
$xpath = new DOMXPath($doc);
$xpathResult = $xpath->query("//a[@href = '../collection?file={$_GET['file']}']/..");
if ($xpathResult === false) {
throw new LogicException('Something went wrong querying the document!');
}
foreach ($xpathResult as $domNode) {
echo 'Link text: ' . htmlentities($domNode->textContent) . PHP_EOL;
}https://stackoverflow.com/questions/18157727
复制相似问题