Закончено получение результата поиска из поиска Google, так как у меня не было lat/long.
Пользователь HTML Agility, чтобы извлечь содержимое страницы, отфильтровывал узлы, содержащие «Время», достаточно простой, чтобы первый элемент был необходимым результатом.
Если вы google "time cincinnati oh", вы вернетесь "1:41 pm Пятница (EDT) - Время в Цинциннати, OH" в верхней части страницы. этот блок кода извлекает это. Безопасность, если время не может быть определена, страница поиска показывает только результаты, поэтому первый элемент в массиве, как, «Отображение результатов для„yourSearch“» и т.д.
public void timeZoneUpdate()
{
try
{
arrayToParse.Clear();
string URL = @"https://www.google.com/search?q=time+" + rowCity + "%2C+" + rowState;
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(URL);
myRequest.Method = "GET";
WebResponse myResponse = myRequest.GetResponse();
StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
string result = sr.ReadToEnd();
sr.Close();
myResponse.Close();
//Console.Write(result);
HtmlAgilityPack.HtmlDocument htmlSnippet = new HtmlAgilityPack.HtmlDocument();
htmlSnippet.Load(new StringReader(result));
bool foundSection = false;
foreach (HtmlAgilityPack.HtmlNode table in htmlSnippet.DocumentNode.SelectNodes("//table"))
{
foreach (HtmlAgilityPack.HtmlNode row in table.SelectNodes("tr"))
{
foreach (HtmlAgilityPack.HtmlNode cell in row.SelectNodes("td"))
{
if (cell.InnerText.Contains("Time"))
{
foundSection = true;
}
if (foundSection)
{
//Console.WriteLine("Cell value : " + cell.InnerText);
arrayToParse.Add(cell.InnerText);
}
}
}
}
retrievedTimeZone = arrayToParse[0].ToString().Split('-')[0].Trim();
if(retrievedTimeZone.Contains("Showing"))
{
retrievedTimeZone = "Undetermined";
}
}
относящиеся к: http://stackoverflow.com/questions/55901/web-service-current-time-zone-for-a-city –