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

How to remove whitespace from string using php

Remove All Special Characters From String PHP

Redirecting HTTP to HTTPS with PHP

Convert Base64 string to an image file

Tools:

Crypto Currency

PHPKIDA provides free online the best real-time crypto market price, news, predictions, index with graphs & historical data for 2000+ coins including bitcoin, ethereum, & altcoins from major cryptocurrency exchanges.

Visite Tool

Icon Generator

PHPKIDA provides free online icon generator. Our icon generator help you to edit, modify, resize and customize icon for your website and applications. Convert to a shap you like add icon border, you can change icon border color, border size, background color, icon shadow, icons color, icon size in your own way and save it as a png image.

Visite Tool

Youtube Video Downloader

PHPKIDA provides Free online YouTube video downloader to download YouTube videos quickly in MP4, 3GP, and more. Search your video and free fast download youtube videos.

Visite Tool

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.