PHP Retrieves all links on the specified URL page, and php retrieves the url page
Form: http://www.uphtm.com/php/253.html
This is actually a common practice for our developers. We used to crawl links from other websites. Today, a friend sorted out a PHP code to retrieve all the link functions on the specified URL page, let's take a look.
The following code obtains all links on the specified URL page, that is, the href attribute of all a tags:
This code will get the href attribute of all a tags, but the href attribute value is not necessarily a link. We can filter it and only keep the link address starting with http:
The fopen () function reads all links in a specified webpage and counts the number of links. This Code is applicable to some areas where the webpage content needs to be collected. In this example, Baidu homepage is read as an example, find all links on the Baidu homepage. The Code has been tested and is fully available:
Form: http://www.uphtm.com/php/253.html