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

Your email address will not be published. Required fields are marked *

Related Posts: You may like

How to login with LinkedIn oAuth2 in PHP

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

Redirecting HTTP to HTTPS with PHP

Convert Base64 string to an image file

Fullscreen Background Video Using HTML5 And CSS

How to get form filed names with values php

how to get current week start date and end date in php

PHPKIDA Offering Free Tools:

INSTA DOWNLOADER

Free online tool to download Instagram videos, photos and save Instagram videos, photos to your device. It's free & easy to use.

Download Now

CURRENCY CONVERTER

Our real time currency converter calculator will convert your money based on current values from around the world. It's free & easy to use.

Convert Now

ROBOST.TXT GEN.

Create robots txt file that help search engines to crawling and indexing your site with help of our free online Robots.txt Generator tool.

Create Now

HTML MINIFIER

Free online tool to minify or compress html code and reduce the size of html code in few clicks. It's free & easy to use.

Minify Now

CSS MINIFIER

Free online tool to minify or compress css code and reduce the size of css code in few clicks. It's free & easy to use.

Minify Now

JAVASCRIPT MINIFIER

Free online tool to minify or compress javascript code and reduce the size of javascript code in few clicks. It's free & easy to use.

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.