Simple code for capturing page information in php? Use the phpDOM function to capture simple single page information & nbsp) & lt ;? Phperror_reportin 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 ();
?> Mj133233 on the first floor 2011-10-11
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service