public void FullLocation(PNLocationInfo localInfo) { string queryUrl = "http://www.ip138.com:8080/search.asp?action=mobile&mobile=" + localInfo.PhoneNumber; Uri queryUri = new Uri(queryUrl); try { Stream stream = this.mWebClient.OpenRead(queryUri); StreamReader sr = new StreamReader(stream, Encoding.Default); string result = sr.ReadToEnd(); this.mHtmlDoc.LoadHtml(result); } catch (Exception ex) { localInfo.Result = "访问服务时出错:" + ex.Message; return; } HtmlAgilityPack.HtmlNodeCollection nodeCol = this.mHtmlDoc.DocumentNode.SelectNodes("//table/tr/td[@class='tdc2']"); if (nodeCol.Count <= 0) { localInfo.Result = "服务返回结构不正确"; return; } localInfo.PhoneNumber = nodeCol[0].FirstChild.InnerText; localInfo.Segment.Province = nodeCol[1].FirstChild.InnerText; localInfo.Segment.CardType = nodeCol[2].FirstChild.InnerText; localInfo.Segment.AreaCode = nodeCol[3].FirstChild.InnerText; localInfo.Segment.PostCode = nodeCol[4].FirstChild.InnerText; try { string[] pc = localInfo.Segment.Province.Split(new string[] { " " }, StringSplitOptions.None); //为了保留原始信息,用这个顺序 localInfo.Segment.City = pc[1]; localInfo.Segment.Province = pc[0]; } catch (Exception ex) { localInfo.Segment.City = ex.Message; } localInfo.Result = string.Empty; }
public void FullLocation(PNLocationInfo localInfo) { this.mHtmlDoc.OptionOutputOriginalCase = true; string queryUrl = "http://api.showji.com/Locating/www.showji.com.aspx?m=" + localInfo.PhoneNumber; Uri queryUri = new Uri(queryUrl); try { Stream stream = this.mWebClient.OpenRead(queryUri); StreamReader sr = new StreamReader(stream, Encoding.UTF8); string result = sr.ReadToEnd(); this.mHtmlDoc.LoadHtml(result); } catch (Exception ex) { localInfo.Result = "访问服务时出错:" + ex.Message; return; } HtmlAgilityPack.HtmlNode rootNode = this.mHtmlDoc.DocumentNode.SelectSingleNode("//queryresponse"); if (rootNode == null) { localInfo.Result = "服务返回结构不正确"; return; } HtmlAgilityPack.HtmlNode nodeQueryResult = rootNode.SelectSingleNode("queryresult"); if (nodeQueryResult == null || string.Equals(nodeQueryResult.InnerText, "false", StringComparison.CurrentCultureIgnoreCase)) { localInfo.Result = "服务没有结果返回"; return; } localInfo.PhoneNumber = rootNode.SelectSingleNode("mobile").InnerText; localInfo.Segment.Province = rootNode.SelectSingleNode("province").InnerText; localInfo.Segment.City = rootNode.SelectSingleNode("city").InnerText; localInfo.Segment.AreaCode = rootNode.SelectSingleNode("areacode").InnerText; localInfo.Segment.PostCode = rootNode.SelectSingleNode("postcode").InnerText; localInfo.Segment.CardType = rootNode.SelectSingleNode("corp").InnerText; localInfo.Segment.CardType += " " + rootNode.SelectSingleNode("card").InnerText; localInfo.Result = string.Empty; }
public void FullLocation(PNLocationInfo localInfo) { string queryUrl = "http://www.baidu.com/s?wd=" + localInfo.PhoneNumber; try { Stream stream = this.mWebClient.OpenRead(queryUrl); StreamReader sr = new StreamReader(stream, Encoding.UTF8); string responseString = sr.ReadToEnd(); this.mHtmlDoc.LoadHtml(responseString); } catch (Exception ex) { localInfo.Result = "访问服务时出错:" + ex.Message; return; } HtmlAgilityPack.HtmlNode selectedNode = this.mHtmlDoc.DocumentNode.SelectSingleNode("//div[@class='op_mp_r']/span[2]"); if (selectedNode == null) { localInfo.Result = "服务返回结构不正确"; return; } string[] result = selectedNode.InnerText.Split(new string[] { " " }, StringSplitOptions.None); localInfo.Segment.City = result[1]; localInfo.Segment.Province = result[0] == "" ? localInfo.Segment.City : result[0]; //直辖市 localInfo.Segment.CardType = result[3]; localInfo.Segment.AreaCode = ""; localInfo.Segment.PostCode = ""; localInfo.Result = string.Empty; }