Home > Backend Development > PHP Tutorial > PHP gets all links in the specified URL page, php gets the url page_PHP tutorial

PHP gets all links in the specified URL page, php gets the url page_PHP tutorial

WBOY
Release: 2016-07-13 09:57:13
Original
909 people have browsed it

PHP gets all the links in the specified URL page, php gets the url page

form: http://www.uphtm.com/php/253.html

This thing is actually commonly used by us developers. We used it when we were doing a project to capture friendly links from other websites. Today I saw a friend compiled a PHP function to get all the link functions in the specified URL page. We sorted it out Get up and take a look.

The following code can obtain all links in 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 the links in the specified web page and counts the number. This code is suitable for use in some places where the content of the web page needs to be collected. In this example, reading the Baidu home page is used as an example to find out the links in the Baidu home page. All link addresses and codes have been tested and fully usable:

form:http://www.uphtm.com/php/253.html

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/984440.htmlTechArticlePHP gets all the links in the specified URL page, php gets the url page form: http://www.uphtm. com/php/253.html This thing is actually commonly used by us developers. We used to do one to crawl other...
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template