private void SearchFromSodu(SearchResult searchResult, HttpContentDownloader downloader, Uri searchUri) { downloader.Download(searchUri, ar => { try { //At this step, we can get the index page in the search engine var state = (RequestState)ar.AsyncState; state.stopTimer = true; var response = (HttpWebResponse)state.Request.EndGetResponse(ar); response.GetResponseStream(); var parser = new SoduSearchResultPageParser(); SearchBookResult = parser.Parse(response.GetResponseStream(), searchResult) as List<SearchResult>; ProgressIndicatorHelper.StopProgressIndicator(); } catch (WebException e) { if (e.Status == WebExceptionStatus.RequestCanceled) { throw new TimeoutException("连接sodu.org超时,可尝试更换搜书引擎"); } } }); }
private void ProcessBookElement(HtmlNode trElement, List<SearchResult> SearchResultUrlList) { if (trElement.Name != "tr") return; var item = new SearchResult(); var tdElements = trElement.DescendantNodes().Where(n => n.Name == "td").ToArray(); if (tdElements.Length == 5) { //Parse Book name and index page url var aElement = tdElements[1].DescendantNodes().Where(n => n.Name == "a").First(); if (aElement != null) { item.IndexPageUri = new Uri("http://www.xiaoelang.com" + aElement.Attributes["href"].Value, UriKind.Absolute); item.BookName = aElement.InnerText.Trim(); item.Book = new Book(); item.Book.Name = item.BookName; } //Parse last update chapter name aElement = tdElements[2].DescendantNodes().Where(n => n.Name == "a").First(); if (aElement != null) { item.LastUpdateChapterName = aElement.InnerText.Trim(); } //Parse last update time //<td class="xt" align="center" valign="middle" width="78">2011-08-26</td> } SearchResultUrlList.Add(item); }
public void Search(string keyword) { var searchEngine = GetSearchEngine(); var searchUri = new Uri(searchEngine.SearchUri, UriKind.Absolute); if (searchEngine.Type == SearchEngineType.Sodu) { searchUri = new Uri(String.Format(searchEngine.SearchUri, HttpUtility.UrlEncode(keyword)), UriKind.Absolute); } var downloader = new HttpContentDownloader(); DownloaderList.Add(downloader); var searchResult = new SearchResult(); if (searchEngine.Type == SearchEngineType.Sodu) { SearchFromSodu(searchResult, downloader, searchUri); } if (searchEngine.Type == SearchEngineType.Xiaoelang) { SearchFromXiaoelang(keyword, searchResult, downloader, searchUri); } }
private void SearchFromXiaoelang(string keyword, SearchResult searchResult, HttpContentDownloader downloader, Uri searchUri) { downloader.DownloadPost(searchUri, "keyword", keyword, ar => { try { //At this step, we can get the index page in the search engine var state = (RequestState)ar.AsyncState; state.stopTimer = true; var response = (HttpWebResponse)state.Request.EndGetResponse(ar); response.GetResponseStream(); var parser = new XiaoelangSearchResultPageParser(); SearchBookResult = parser.Parse(response.GetResponseStream(), searchResult) as List<SearchResult>; } catch (WebException e) { if (e.Status == WebExceptionStatus.RequestCanceled) throw new TimeoutException("连接xiaoelang.com超时,请尝试更换搜书引擎"); } }); }
public void GetBookSiteLink(SearchResult searchResult) { var searchEngine = GetSearchEngine(); Uri soduBookLatestUpdatePage = searchResult.IndexPageUri; var downloader = new HttpContentDownloader(); DownloaderList.Add(downloader); downloader.Download(soduBookLatestUpdatePage, ar => { //At this step, we can get the index page in the search engine var state = (RequestState)ar.AsyncState; var response = (HttpWebResponse)state.Request.EndGetResponse(ar); response.GetResponseStream(); if (searchEngine.Type == SearchEngineType.Sodu) { var parser = new SoduBookLastestUpdatePageParser(); BookList = parser.Parse(response.GetResponseStream(), searchResult.Book) as List<Book>; } if (searchEngine.Type == SearchEngineType.Xiaoelang) { var parser = new XiaoelangBookLastestUpdatePageParser(); BookList = parser.Parse(response.GetResponseStream(), searchResult.Book) as List<Book>; } }); }