using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
public static void Main()
string url = "https://www.comms-care.com/";
ScrapeCompanyDetails("comms-care");
public static void TagRead(string url)
var httpClient = new HttpClient();
var htmlREsponse = httpClient.GetAsync(new Uri(url)).Result;
var htmlDocument = new HtmlDocument();
htmlDocument.LoadHtml(html);
var ogTags = new Dictionary<string, string>
{ "title", htmlDocument.DocumentNode.SelectSingleNode("//meta[@property='og:title']")?.Attributes["content"]?.Value },
{ "description", htmlDocument.DocumentNode.SelectSingleNode("//meta[@property='og:description']")?.Attributes["content"]?.Value },
{ "image", htmlDocument.DocumentNode.SelectSingleNode("//meta[@property='og:image']")?.Attributes["content"]?.Value },
{ "url", htmlDocument.DocumentNode.SelectSingleNode("//meta[@property='og:url']")?.Attributes["content"]?.Value }
Console.WriteLine($"title: {ogTags["title"]}");
Console.WriteLine($"description: {ogTags["description"]}");
Console.WriteLine($"image: {ogTags["image"]}");
Console.WriteLine($"url: {ogTags["url"]}");
public static void ScrapeCompanyDetails(string companyName)
string searchUrl = "https://www.google.com/search?q=" + companyName;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(searchUrl);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader streamReader = new StreamReader(response.GetResponseStream());
string html = streamReader.ReadToEndAsync().Result;
HtmlDocument document = new HtmlDocument();
HtmlNode resultNode = document.DocumentNode.SelectSingleNode("//div[@class='g']");
HtmlNode linkNode = resultNode.SelectSingleNode(".//a[@href]");
string link = linkNode.Attributes["href"].Value;
string companyUrl = link.Substring(link.IndexOf('=') + 1, link.IndexOf('&') - link.IndexOf('=') - 1);
HttpWebRequest companyRequest = (HttpWebRequest)WebRequest.Create(companyUrl);
HttpWebResponse companyResponse = (HttpWebResponse)companyRequest.GetResponse();
StreamReader companyStreamReader = new StreamReader(companyResponse.GetResponseStream());
string companyHtml = companyStreamReader.ReadToEndAsync().Result;
HtmlDocument companyDocument = new HtmlDocument();
companyDocument.LoadHtml(companyHtml);
var companyDetails = new Dictionary<string, string>
{ "address", companyDocument.DocumentNode.SelectSingleNode("//address").InnerText },
{ "phone", companyDocument.DocumentNode.SelectSingleNode("//phone").InnerText },
{ "website", companyUrl }
Console.WriteLine($"name: {companyDetails["name"]}");
Console.WriteLine($"address: {companyDetails["address"]}");
Console.WriteLine($"phone: {companyDetails["phone"]}");
Console.WriteLine($"website: {companyDetails["website"]}");