Simple code for capturing page information in php? Use the phpDOM function to capture simple single page information & nbsp) & lt ;? Phperror_reporting (E_ERROR); $ pagesfile_get_contents (www. php100. simple code for capturing page information in php
? Use the php DOM function to capture simple single-page information (here we do our best to capture the tag, the function is implemented, but the extension page link crawling is not implemented, you are welcome to criticize and guide)
Error_reporting (E_ERROR );
$ Pages = file_get_contents ('http: // www.php100.com ');
// $ Pages = htmlspecialchars ($ pages );
$ Doc = new DOMDocument ();
$ New_doc = new DOMDocument ('1. 0', 'utf-8 ');
$ Doc-> loadhtml ($ pages );
$ Dom = $ doc-> getElementsByTagName ('A ');
For ($ I = 0; $ I <$ dom-> length; $ I ++ ){
$ Node = $ new_doc-> createElement ('A', $ dom-> item ($ I)-> nodeValue );
$ Newnode = $ new_doc-> appendChild ($ node );
$ Newnode-> setAttribute ('href ', $ dom-> item ($ I)-> getAttribute ('href '));
$ Newnode-> setAttribute ('style', 'display: block; margin-left: 30px; '); // echo $ dom-> item ($ I) -> getAttribute ('src ').'
';
}
Echo $ new_doc-> saveHTML ();
?>
1st floor mj133233 2011-10-11
Build the first floor by yourself