[英]How to get AJAX RESPONSE text from DIV using PHP DOMDocument?
我必須從站點的div中恢復一些文本。 div的結構如下:
HTML標記:
<div class="content" id="content">
Loading.....
</div>
我猜是在頁面加載時DIV的內容通過AJAX函數更改。 並且DIV的內容在1或2秒后發生更改。HTML結構變為:
<div class="content" id="content">
<span class"parent">
<span class="child">
<span class="sometext">HERE IS SOME TEXT</span>
</span>
</span>
</div>
當我使用以下PHP函數(crawl_page)來獲取具有ID內容的div的HTML時,它始終會返回(Loading ..)應該是的。
我需要的是更新的html代碼,無論如何要實現這一目標?
function crawl_page($url)
{
$doc = new DOMDocument();
$doc->loadHTMLFile($url);
$xpath = new DOMXPath($doc);
$element = $xpath->query("//*[@id='content']")->item(0);
echo $element->nodeValue;
}
crawl_page("http://example.com/#1:7");
我希望它能工作。 並從以下網址下載包含文件
http://sourceforge.net/projects/simplehtmldom/files/
<?php
// example of how to use basic selector to retrieve HTML contents
include('../simple_html_dom.php');
// get DOM from URL or file
$html = file_get_html('http://example.com/#1:7');
// find all link
foreach($html->find('a') as $e)
echo $e->href . '<br>';
// find all image
foreach($html->find('img') as $e)
echo $e->src . '<br>';
// find all image with full tag
foreach($html->find('img') as $e)
echo $e->outertext . '<br>';
// find all div tags with id=gbar
foreach($html->find('div#content') as $e)
echo $e->innertext . '<br>';
// find all span tags with class=gb1
foreach($html->find('span.gb1') as $e)
echo $e->outertext . '<br>';
// find all td tags with attribite align=center
foreach($html->find('td[align=center]') as $e)
echo $e->innertext . '<br>';
// extract text from table
echo $html->find('td[align="center"]', 1)->plaintext.'<br><hr>';
// extract text from HTML
echo $html->plaintext;
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.