public Tuple <string, List <ScriptResult> > Run(string url, Action <string> update = null) { foreach (var model in models) { if (url.StartsWith(model.URLSpecifier)) { var result = new ScriptResult(); HtmlDocument document = new HtmlDocument(); document.LoadHtml(Net.NetCommon.DownloadString(url)); HtmlNode node = document.DocumentNode; if (!model.UsingDriver) { result.Title = HtmlCAL.Calculate(model.TitleCAL, node)[0]; if (model.UsingSub) { return(Tuple.Create(result.Title, run_subs(model, node, update))); } else { update?.Invoke($"{result.Images.Count}개의 이미지를 찾았습니다."); result.Images = HtmlCAL.Calculate(model.ImagesCAL, node); result.FileNames = HtmlCAL.Calculate(model.FileNameCAL, node); return(Tuple.Create(result.Title, new List <ScriptResult> { result })); } } } } return(null); }
private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { try { Result.Text = string.Join("\r\n", HtmlCAL.Calculate(Pattern.Text, root_node)); } catch (Exception ex) { Result.Text = ex.Message + "\r\n" + ex.StackTrace; } }
private List <ScriptResult> run_subs(ScriptModel model, HtmlNode root_node, Action <string> update) { var result = new List <ScriptResult>(); var sub_urls = HtmlCAL.Calculate(model.SubURLCAL, root_node); List <string> titles = null; if (!string.IsNullOrEmpty(model.SubURLTitleCAL)) { titles = HtmlCAL.Calculate(model.SubURLTitleCAL, root_node); } update?.Invoke($"{sub_urls.Count}개의 하위 항목을 찾았습니다."); for (int i = 0; i < sub_urls.Count; i++) { HtmlDocument document = new HtmlDocument(); document.LoadHtml(Net.NetCommon.DownloadString(sub_urls[i])); HtmlNode node = document.DocumentNode; var title = ""; if (titles != null) { title = titles[i]; } else { title = HtmlCAL.Calculate(model.SubURLTitleCAL, node)[0]; } result.Add(new ScriptResult { URL = sub_urls[i], Title = title, Images = HtmlCAL.Calculate(model.SubImagesCAL, node), FileNames = HtmlCAL.Calculate(model.SubFileNameCAL, node) }); update?.Invoke($"이미지 목록을 만드는 중입니다...[{i+1}/{sub_urls.Count}]"); Thread.Sleep(model.PerDelay); } return(result); }
public _Array <string> cal(string pattern) => new _Array <string>(HtmlCAL.Calculate(pattern, node).ToArray());