PDA

View Full Version : مبتدی: نمایش موقعیت سایت در گوگل(google position search)



nassim0
دوشنبه 08 مرداد 1397, 19:14 عصر
با سلام خدمت دوستان
میخواستم موقعیت سایت بر اساس جستجوی کلمه کلیدی خاص توی گوگل رو دریافت کنم . کد زیر رو دارم اما در هر تستی بهم صفر نشون میده . ممنون میشم راهنماییم کنید .



public static int GetPosition(Uri url, string searchTerm)
{
string raw = "http://www.google.com/search?num=39&q={0}&btnG=Search";
string search = string.Format(raw, HttpUtility.UrlEncode(searchTerm));
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(search);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
using (StreamReader reader = new StreamReader(response.GetResponseStream(),Encoding .ASCII))
{
string html = reader.ReadToEnd(); return FindPosition(html, url);
}
}
}


private static int FindPosition(string html, Uri url)
{
string lookup = "(<h2 class=r><a href =\")(\\w+[a-zA-Z0-9.-?=/]*)";
MatchCollection matches = Regex.Matches(html,lookup);
for (int i = 0; i<matches.Count;i++)
{ string match = matches[i].Groups[2].Value;
if (match.Contains(url.Host))
return i + 1;
} return 0;
}




Uri url = new Uri("https://en.wiktionary.org/wiki/soft");
int position = GetPosition(url, "soft");