/// <summary> /// 开始下载本子 /// </summary> /// <param name="dicUrls">下载目标</param> /// <param name="targetText">下载目录</param> public void DownLoadImg(Dictionary <string, string> dicUrls, string targetText) { //制定本子的存放目录 string path = Path.Combine(this.SaveFolder, targetText); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } WebClient webClient = new WebClient(); //设置请求头 webClient.Headers["User-Agent"] = @"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"; //开始遍历下载 if (dicUrls.Count > 0) { int indexPage = 0; foreach (var eachPage in dicUrls) { indexPage++; lblTip.Text = string.Format("正在下载第{0}页,请耐心等待.....", indexPage); try { var targetPage = new JumonyParser().LoadDocument(eachPage.Value).Find("#i3 img"); if (targetPage.FirstOrDefault() == null) { continue; } string imgToDownload = targetPage.FirstOrDefault().Attribute("src").AttributeValue.ToString(); string destFileName = Path.Combine(path, eachPage.Key + ".jpg"); webClient.DownloadFile(imgToDownload, destFileName); } catch (Exception ex) { continue; } } btnDownload.Text = "点击下载"; btnDownload.Enabled = true; lblTip.Text = string.Empty; MessageBox.Show("下载完成,快去看看吧hentai", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //下载完成,提示 System.Diagnostics.Process.Start("Explorer.exe", path); } }
private void btnDownload_Click(object sender, EventArgs e) { //root url https://e-hentai.org this.lblTip.Text = string.Empty; string targetUrl = this.txtTargetUrl.Text; //本子根目录 string targetText = this.txtTargetUrl.Text; //获取本子的标题 string savePath = this.txtSaveDest.Text; if (string.IsNullOrEmpty(savePath)) { MessageBox.Show("请先选择本子的存放目录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (string.IsNullOrEmpty(targetUrl)) { MessageBox.Show("请先选择下载地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { btnDownload.Text = "正在下载"; btnDownload.Enabled = false; var targetObj = new JumonyParser().LoadDocument(targetUrl).Find("#gj"); if (targetObj != null && targetObj.FirstOrDefault() != null) { targetText = targetObj.FirstOrDefault().InnerText(); } RunAsync(() => { GetAllLinkPage(targetUrl, targetText); }); } catch (Exception ex) { MessageBox.Show("发生了我也不想的错误.....:" + ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 查询当前请求IP地址 /// </summary> /// <param name="ip"></param> /// <returns></returns> private string IpAddress(string ip) { const string searchIp = "http://1111.ip138.com/ic.asp"; ResponseItem myIp = new HttpRequestHelper().RequestDataByPost( new RequestItem { RequestUrl = searchIp, Method = HttpMethodEnum.Get, AutoRedirect = false, Timeout = 3 * 1000, ProxyInfo = new ProxySetInfo { ProxyIp = ip } }); if (myIp == null || !myIp.ResultHtml.Contains("IP是")) { return(null); } var documentmyIp = new JumonyParser().Parse(myIp.ResultHtml).Find("center"); var isCenter = documentmyIp.FirstOrDefault(); return(isCenter.InnerText()); }