private void Chrome_AddressChanged(object sender, AddressChangedEventArgs e) { SetAddress(e.Address); if (e.Address.Contains(HOME_PAGE_URL)) { OnStateChange?.Invoke(Enums.StateLogType.TaoBaoSignSuccess, "登录京东成功"); if (NoLoadCids.Count == 0) { OnStateChange?.Invoke(Enums.StateLogType.JdCouponAddedDb, "暂无新数据库"); } var cid = NoLoadCids.FirstOrDefault(); LoadAddress(cid.CidUrls.FirstOrDefault().Url); } }
public async void Download() { if (!EnableRun) { return; } try { //获取自己和所有二级代理,今天采集的京东 var proxys = ProxyUsers; if (proxys.Count > 0) { var scrPage = await chrome.EvaluateScriptAsync("(function (){ return $('.page-num').text()})()"); var strPage = scrPage.Result.ToString().SplitToArray <int>('/'); Page.Number = strPage[0]; Page.Total = strPage[1]; var proxy = proxys.FirstOrDefault(); chrome.ExecuteScriptAsync("$('#bitch-checkbox').click()"); chrome.ExecuteScriptAsync("$('.btn-bitch').click()"); Thread.Sleep(100); chrome.ExecuteScriptAsync("$('#adtType_4').click()"); try { await chrome.Wait("#spaceName option:nth-child(2)", 10000, async() => { chrome.ExecuteScriptAsync("$('#protocol_1,#channel_2').click()"); var html = await chrome.GetSourceAsync(); var doc = CQ.CreateDocument(html); var spaceNames = doc.Select("#spaceName option") .Select(s => WebUtility.HtmlDecode(s.InnerText).Trim()) .ToList(); var index = spaceNames.IndexOf(proxy.PhoneNumber); if (index > 0) { chrome.ExecuteScriptAsync($"$('#spaceName option:nth-child({index + 1})').prop('selected',true);"); } else { chrome.ExecuteScriptAsync($"$('#kind_2').click();$('#positionName').val('{proxy.PhoneNumber}');"); } downloadHandler.Set(prefix: $"{proxy.PhoneNumber}_{NoLoadCids.FirstOrDefault().CidUrls.FirstOrDefault().Cid}_", suffix: $"_{Page.Number}_{Page.Total}"); chrome.ExecuteScriptAsync("$('#getcode-btn').click()"); }); } catch (Exception ex) { OnStateChange?.Invoke(Enums.StateLogType.JdCouponColumnError, "找不到广告位"); LoadAddress(chrome.Address); } } else { //OnStateChange?.Invoke(Enums.StateLogType.TaoBaoCouponAddDbComplated, $"未检测到有新淘宝商品"); //Task task = new Task(() => //{ // System.Threading.Thread.Sleep(5 * 60 * 1000); // chrome.Load(COUPON_DOWNLOAD_URL); //}); //task.Start(); } } catch (Exception ex) { SystemBase.WriteLog($"加载错误{ex.Message}", "error"); } }