public List <WandoujiaExportModel> getPageModelByCate(int cateId, int pageIndex) { //var result = new List<WandoujiaExportModel>(); var result = new ConcurrentQueue <WandoujiaExportModel>(); string url = $"https://www.wandoujia.com/wdjweb/api/category/more?catId={cateId}&subCatId=0&page={pageIndex}"; var html = HttpUtil.GetHtml(url); var pagemodel = JsonConvert.DeserializeObject <CatePageModel>(html); if (pagemodel.data != null && !String.IsNullOrEmpty(pagemodel.data.content)) { var doc = NSoup.NSoupClient.Parse(pagemodel.data.content); var apps = doc.Select("li"); apps.AsParallel().ForAll(item => { WandoujiaExportModel model = new WandoujiaExportModel { PackageName = item.Attr("data-pn"), AppName = item.Select("div.app-desc>h2>a").Text, AppUrl = item.Select("div.app-desc>h2>a").Attr("href"), DownloadCount1 = getInstallCount(item.Select("div.app-desc>div.meta>span.install-count").Text), FileSize = item.Select("div.app-desc>div.meta").Select("span").Last().Text() }; result.Enqueue(model); }); } var list = result.Distinct().ToList(); list.AsParallel().ForAll(model => { var model2 = getAppDetail(model.AppUrl); model.DownloadCount2 = model2.DownloadCount2; model.UpdateTime = model2.UpdateTime; }); return(list); }
public WandoujiaExportModel getAppDetail(String url) { var html = HttpUtil.GetHtml(url); if (String.IsNullOrEmpty(html)) { Thread.Sleep(1000); html = HttpUtil.GetHtml(url); } var doc = NSoup.NSoupClient.Parse(html); var time = doc.Select("div.app-info-wrap .update-time").Attr("datetime"); var installCount = doc.Select("div.app-info-wrap .install").Text.Trim(); var result = new WandoujiaExportModel { UpdateTime = time, DownloadCount2 = getInstallCount(installCount) }; return(result); }