Extract URLs from the website using php

Extract URLs from the website using php

Extract URLs from an URL is used in many cases, creating a sitemap extracting website URL is a best example of them.
In this Tutorial I will show you how to Extract URLs from the website, it’s very simple you can easily extract all URLs from a web page using PHP. Here we will provide short and simple code to extract all URLs from a web page in PHP. I have used simple DOM concept to find the html data from URL. file_get_contents and loadHTML is used to retrieve the html for URL and DOMXPath to grab it. This PHP code helps to extract all the links from a web page URL. Find this code below.

PHP Code for get URLs from the website

<?php
// Webpage URL
$webUrl='http://www.quizwine.com/';
$html = file_get_contents($webUrl);
 
$dom = new DOMDocument();
@$dom->loadHTML($html);
 
// get all the content on the page
$xpath = new DOMXPath($dom);
 
// finding the a tag
$hrefs = $xpath->evaluate("/html/body//a");
 
//Loop to display all the links
for ($i = 0; $i < $hrefs->length; $i++)
{
 $href = $hrefs->item($i);
 $url = $href->getAttribute('href');
 echo $url."<br>";
}
?>

Keywords: How to Extract All URLs from a Web Page using PHP, Find Out All Links In any Website using PHP, How to get all urls from page using php, Find Links on Webpage using PHP, How to get all the page links fro URL using PHP, Use PHP to Crawl Links from Another Website, php, extract links, find links, extract url, find urls, get urls, get links

Leave a Reply

Related Posts: You may like

Extract Total Number of Image And Missing Alt Attribute using php

How to extract Heading tags using PHP from string

How to remove whitespace from string using php

Remove All Special Characters From String PHP

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Download Instagram Videos & Photos.

Download Now

CURRENCY CONVERTER

Real Time Currency Converter

Convert Now

ROBOST.TXT GEN.

Robots.txt File Creater

Create Now

HTML MINIFIER

Compress yout HTML Code

Minify Now

CSS MINIFIER

Compress yout CSS Code

Minify Now

JAVASCRIPT MINIFIER

Compress yout JavaScript Code

Minify Now

Sign up for weekly update

Milkshake is almost ready. If you're interested in testing it out, then sign up below to get exclusive access.