开发者

Extract HTML of a Scraped Page Using PHP's DOM

Is it possible to create HTML output from the contents of an HTML snippet that has been extracted via PHP's DOM tools (e.g. $div = $dom->getElementsByTagName('table')->item(0);) such that the HT开发者_Go百科ML created contains just the elements with specified tag name, and their descendants?

Otherwise, are there perhaps any other ways to easily extract a snippet of HTML from the full HTML of a page? I just want to extract the first table of a page I scraped, and display just that table and its content.


Yes, you can pass a node to DOMDocument::saveXML()

echo $dom->saveXml($div);

which will then give you the outerHTML of the node

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜