private List <DecodeResult> DecodeResult(string result, SpiderFormula formula) { List <DecodeResult> list = new List <DecodeResult>(); string text = result.Substring(result.IndexOf("<div class=\"results\">")) .Replace("\r", " ").Replace("\\n", " ").Replace("\n", " ") .Replace("<em>", "").Replace("</em>", "") .Replace("<!--awbg5-->", "").Replace("<!--red_beg-->", "") .Replace("<!--red_end-->", ""); var matches = regex.Matches(text); if (matches == null) { return(null); } foreach (Match match in matches) { var d = new DecodeResult(); d.searchengine = SearchEngineName; d.ipaddress = match.Groups[3].Value.ToString(); d.no = match.Groups[2].Value.ToString(); d.title = match.Groups[4].Value.ToString(); list.Add(d); } return(list); }
public SpiderFormula UpdateFormula() { if (spiderFormula == null) { spiderFormula = new SpiderFormula(); spiderFormula.searchengine = comboBoxSearchEngine.Text; spiderFormula.keyword = textBoxKeyword.Text; spiderFormula.interestcontentregex = textBoxKeywordregex.Text; spiderFormula.name = textBoxName.Text; spiderFormula.continuepage = checkBoxContinuePage.Checked; spiderFormula.continuepagecount = Convert.ToInt32(numericUpDownPageCount.Value); spiderFormula.continuepageregex = textBoxPageRegex.Text; return(spiderFormula); } else { spiderFormula.searchengine = comboBoxSearchEngine.Text; spiderFormula.keyword = textBoxKeyword.Text; spiderFormula.interestcontentregex = textBoxKeywordregex.Text; spiderFormula.name = textBoxName.Text; spiderFormula.continuepage = checkBoxContinuePage.Checked; spiderFormula.continuepagecount = Convert.ToInt32(numericUpDownPageCount.Value); spiderFormula.continuepageregex = textBoxPageRegex.Text; return(null); } }
public SpiderFormulaControl(SpiderFormula i) { InitializeComponent(); if (i != null) { spiderFormula = i; comboBoxSearchEngine.Text = i.searchengine; textBoxKeyword.Text = i.keyword; textBoxKeywordregex.Text = i.interestcontentregex; textBoxName.Text = i.name; checkBoxContinuePage.Checked = i.continuepage; numericUpDownPageCount.Value = i.continuepagecount; textBoxPageRegex.Text = i.continuepageregex; numericUpDownPageCount.Enabled = checkBoxContinuePage.Checked; textBoxPageRegex.Enabled = checkBoxContinuePage.Checked; } }
public async Task Run(SpiderFormula formula, FlowLayoutPanel panel) { if (formula == null) { return; } int pagecount = 1; if (formula.continuepage) { pagecount = formula.continuepagecount; } Regex titleRegex = new Regex(formula.interestcontentregex, RegexOptions.Compiled, Regex.InfiniteMatchTimeout); for (int i = 0; i < pagecount; i++) { if (!hasUri) { query.SetUri("http://www.so.com"); hasUri = true; } string result = await query.HttpClientDoGet("/s?q=" + formula.keyword + "&pn=" + (1 + i)); List <DecodeResult> list = DecodeResult(result, formula); if (list == null || list.Count == 0) { continue; } foreach (var item in list) { item.keyword = formula.keyword; if (titleRegex.IsMatch(item.title)) { ranklist.Add(item); } } } foreach (var i in ranklist) { panel.Controls.Add(new NannListItem(i as DecodeResult)); } }
internal void AddNewFormula(SpiderFormula f) => spiderFormulas.Add(f);