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; }
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 Run() { this.mRunning = true; int hitType = 0; IPNLocationSource locationSource = CreateLocationSource(); while (this.mPNQueue.Count > 0) { if (this.mRunning == false) { break; } string pn = this.mPNQueue.Dequeue(); PNLocationInfo pnInfo = new PNLocationInfo(); pnInfo.PhoneNumber = pn; pnInfo.Result = "还未查询"; if (this.mSegmengInfoCache.ContainsKey(pnInfo.Segment.NumberSegment)) { pnInfo.Segment = this.mSegmengInfoCache[pnInfo.Segment.NumberSegment]; pnInfo.Result = ""; this.mCacheHitCount++; hitType = 1; } else { locationSource.FullLocation(pnInfo); this.mSegmengInfoCache[pnInfo.Segment.NumberSegment] = pnInfo.Segment; hitType = 0; } this.mPNLocationResultList.Add(pnInfo); OnProcessProgress(pnInfo, hitType); } }
private void OnProcessProgress(PNLocationInfo pnInfo, int hitType) { if (this.ProcessProgressEvent == null) { return; } ProcessProgressEventArgs args = new ProcessProgressEventArgs(); args.Cur = this.mPNLocationResultList.Count; args.Max = this.mPNList.Count; args.PhoneNumberLocation = pnInfo; args.Msg = ""; args.Action = hitType; args.CatchLength = this.mSegmengInfoCache.Count; args.HitCount = this.mCacheHitCount; this.ProcessProgressEvent(args); }
private void OnProcessProgress(PNLocationInfo pnInfo, int hitType) { if (this.ProcessProgressEvent == null) return; ProcessProgressEventArgs args = new ProcessProgressEventArgs(); args.Cur = this.mPNLocationResultList.Count; args.Max = this.mPNList.Count; args.PhoneNumberLocation = pnInfo; args.Msg = ""; args.Action = hitType; args.CatchLength = this.mSegmengInfoCache.Count; args.HitCount = this.mCacheHitCount; this.ProcessProgressEvent(args); }
public void Run() { this.mRunning = true; int hitType = 0; IPNLocationSource locationSource = CreateLocationSource(); while (this.mPNQueue.Count > 0) { if (this.mRunning == false) break; string pn = this.mPNQueue.Dequeue(); PNLocationInfo pnInfo = new PNLocationInfo(); pnInfo.PhoneNumber = pn; pnInfo.Result = "还未查询"; if (this.mSegmengInfoCache.ContainsKey(pnInfo.Segment.NumberSegment)) { pnInfo.Segment = this.mSegmengInfoCache[pnInfo.Segment.NumberSegment]; pnInfo.Result = ""; this.mCacheHitCount++; hitType = 1; } else { locationSource.FullLocation(pnInfo); this.mSegmengInfoCache[pnInfo.Segment.NumberSegment] = pnInfo.Segment; hitType = 0; } this.mPNLocationResultList.Add(pnInfo); OnProcessProgress(pnInfo, hitType); } }