How to get Social Networks from a Websites

Authors: CodeToday | PHP Code | Views: 842 | Posted: 07 AM: 09/05/2017

How to get Social Networks from a WebsitesIf you do not want to get it manually, you can use this tool, you just enter the domain, this tool will filter out for you the social networks that this domain uses. It will filter out social networks like youtube.com, facebook.com, linkedin.com, twitter.com, instagram.com, pinterest.com, plus.google.com .. You can add another social network if want.





Knowledge before viewing this article

  1. curl_init(): Get data before analysis
  2. DOMDocument: In the HTML DOM (Document Object Model), everything is a node
  3. xpath syntax: An XML Path Language (Xpath) expression uses a path notation, like those used in URLs, for addressing parts of an XML document

curl_init()

You can use this function with the previous post here

HTML

<form action="" method="post" class="form-horizontal">
<div class="form-group">
<input type="text" name="domain" id="domain" value="<?=$_POST['domain']?>" class="form-control" placeholder = "Enter domain here ..." required/>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-info">Get Social Networks</button>
</div>
</form>

PHP

When submitting from the html form, the input value will be passed down to php code to retrieve the parsed data

<?
if(isset($_POST['submit'])){

	$url = 'https://www.'.$_POST['domain'];	
	$urlContent = fread_url($url);
	$dom = new DOMDocument();
	@$dom->loadHTML($urlContent);
	$xpath = new DOMXPath($dom);
	$hrefs = $xpath->evaluate("/html/body//a");
		
	for($i = 0; $i < $hrefs->length; $i++){
		$href = $hrefs->item($i);
		$url = $href->getAttribute('href');
		
		if(stristr($url,'youtube.com') == true || 
			stristr($url,'facebook.com') == true || 
			stristr($url,'twitter.com') == true || 
			stristr($url,'linkedin.com') == true ||
			stristr($url,'vimeo.com') == true ||
			stristr($url,'instagram.com') == true ||
			stristr($url,'pinterest.com') == true ||
			stristr($url,'plus.google.com') == true) { 
			$socialLinks[] = $url;
		}
     }
	$urlSocials = @array_unique($socialLinks);	
					  	
echo '<h4 class="text-primary">Social Networks</h4>';
print_r($urlSocials);
}
?>

Full Source Code (index.php)

<?
include 'function.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>How to get Social Networks from a Websites</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h1>How to get Social Networks from a Websites</h1>
// Put html code above here
// Put php code above here
</div>
</body>
</html> 
If you have any questions, please leave a message below