User61956409 posted
Hi Drewstar13,
I am trying to figure out the code (C#) for retrieving backlinks from a website. I have seen it called a "Backlink Checker".
This article explained about “Backlink Checker in C#”, you could check it.
http://www.prodigyproductionsllc.com/articles/programming/backlink-checker-in-c/
The code snippets
namespace BacklinkCounter
{
class Program
{
static void Main(string[] args)
{
string url = "www.prodigyproductionsllc.com";
WebClient wc = new WebClient();
string html = wc.DownloadString(String.Format("http://siteexplorer.search.yahoo.com/search?p={0}&bwm=i&bwmo=&bwmf=s", url));
string linkCount = GetStringInBetween("<span class="btn">Inlinks (", ")</span>", html, false, false)[0];
Console.WriteLine("Link Count: " + linkCount);
Console.ReadLine();
}
public static string[] GetStringInBetween(string strBegin, string strEnd, string strSource, bool includeBegin, bool includeEnd)
{
string[] result = { "", "" };
int iIndexOfBegin = strSource.IndexOf(strBegin);
if (iIndexOfBegin != -1)
{
// include the Begin string if desired
if (includeBegin)
iIndexOfBegin -= strBegin.Length;
strSource = strSource.Substring(iIndexOfBegin + strBegin.Length);
int iEnd = strSource.IndexOf(strEnd);
if (iEnd != -1)
{
// include the End string if desired
if (includeEnd) iEnd += strEnd.Length;
result[0] = strSource.Substring(0, iEnd);
// advance beyond this segment
if (iEnd + strEnd.Length < strSource.Length)
result[1] = strSource.Substring(iEnd + strEnd.Length);
}
}
else
// stay where we are
result[1] = strSource;
return result;
}
}
}
Best Regards,
Fei Han