![](/img/trans.png)
[英]How can i fetch and display the value from external page to parent page's html element
[英]how can i obtain an entire element from an external page?
我如何獲得
<table class="precios">
從另一個URL(www.example.com)轉換為HTML格式? 因為有了DOM,我可以在數組模式下獲取表。
謝謝大家的幫助
假設您沒有跨域問題,則可以使用.load()
:
$container.load('http://www.example.com/path/to/page table.precios');
$container
是一個jQuery對象,您要將表“保存”到其中。
在PHP中,您可以通過以下方式解決它:
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTMLFile('http://www.example.com/path/to/page.html');
libxml_clear_errors();
$xp = new DOMXPath($doc);
$table = $xp->query('//table[@class="precios"]')->item(0);
echo $doc->saveHTML($table);
向該頁面發出AJAX請求,並使用.find()
獲取元素
$.ajax( {
url: myUrl,
success: function(html) {
table = $(html).find(".precious");
}
});
您還可以使用cURL(如果已安裝)並在php中使用DOMDocument類
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.