public void GetHtml(string url, Action <string> callback, Encoding encoding = null) { if (RegularHelper.IsUrl(url)) { this.callback = callback; if (encoding == null) { encoding = Encoding.UTF8; } HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest; //请求方法 req.Method = "GET"; //接受的内容 req.Accept = "text/html"; //用户代理 req.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)"; RequestState rs = new RequestState(req, url); var result = req.BeginGetResponse(new AsyncCallback(ReceivedResource), rs); ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, TimeoutCallback, rs, 120000, true); } else { MessageBox.Show(string.Format("错误的url:{0}", url)); } }
private void callback(string html) { if (html.Contains("识别码搜寻结果")) { //<div class="video" id="vid_javlio354y"><a href="./?v=javlio354y" title="ABP-001 水咲ローラがご奉仕しちゃう超最新やみつきエステ"><div class="id">ABP-001</div> //http://www.javlibrary.com/cn/?v=javlio354y Regex regVideo = new Regex("<div class=\"video\".*" + code + "</div>"); var videoItem = regVideo.Match(html); if (!string.IsNullOrEmpty(videoItem.Value)) { var m = new Regex("<a href=.* title=").Match(videoItem.Value); var t = m.Value.Replace("\"", "").Replace("<a href=./", "").Replace(" title=", ""); HTMLHelper.GetInstance().GetHtml(string.Format("http://www.javlibrary.com/cn/{0}", t), this.callback); } else { MessageBox.Show("找不到影片信息:" + code); } } else { CurrentVideo = VideoManager.GetInstance().CreateVideo(html, code); if (RegularHelper.IsUrl(CurrentVideo.ImgUrl)) { this.coverImg.Dispatcher.Invoke(new Action(delegate { this.coverImg.Source = new BitmapImage(new Uri(CurrentVideo.ImgUrl)); })); } else { Logger.Error(string.Format("{0}的封面地址有误:{1}", CurrentVideo.Code, CurrentVideo.ImgUrl)); } this.nameTextBox.Dispatcher.Invoke(new Action(delegate { this.nameTextBox.Text = CurrentVideo.Name; })); this.birthdayTextBox.Dispatcher.Invoke(new Action(delegate { this.birthdayTextBox.Text = CurrentVideo.Date.ToString("yyyy-MM-dd"); })); this.classTypeTextBox.Dispatcher.Invoke(new Action(delegate { this.classTypeTextBox.Text = CurrentVideo.GetClassString(); })); this.actressTextBox.Dispatcher.Invoke(new Action(delegate { this.actressTextBox.Text = CurrentVideo.GetActressString(); })); } }