PHP Retrieves all links on the specified URL page, and php retrieves the url page

Source: Internet
Author: User

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

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.