public void CreateHtmlSelectorWithNullUri() { // Arrange & Action & Assert Assert.Throws <ArgumentNullException>(() => { var htmlSelector = new HtmlSelector(null); }); }
public void CreateHtmlSelectorWithEmptyUriString() { // Arrange & Action & Assert Assert.Throws <UriFormatException>(() => { var htmlSelector = new HtmlSelector(new Uri("")); }); }
public IEnumerable <User.User> ParseFollowers(IEnumerable <string> nicknames = null) { var listOut = new List <User.User>(); try { if (nicknames == null) { var listNickNames = Regex .Matches(_htmlString, "(?<=title=\")\\w+(?=\" class=\"FPmhX notranslate zsYNt \")") .Cast <Match>() .Select(m => m.Value) .ToList(); _logger.Info($"Find {listNickNames.Count} nicknmes."); foreach (var nickName in listNickNames) { Thread.Sleep(Delay); using (var htmlSelector = new HtmlSelector(new Uri("https://www.instagram.com/" + nickName))) { if (_cancel) { break; } var htmlString = htmlSelector.Run(); var user = new ProfileParser().ParseObject <User.User>(htmlString); listOut.Add(user); OnProcessParser(new ParserProcessEventArgs(listNickNames.Count, listOut.Count)); } } _logger.Info($"Result list of users is {listOut.Count}."); } else { var listNickNames = nicknames.ToList(); foreach (var nickname in listNickNames) { Thread.Sleep(Delay); using (var htmlSelector = new HtmlSelector(new Uri("https://www.instagram.com/" + nickname))) { if (_cancel) { break; } var htmlString = htmlSelector.Run(); var user = new ProfileParser().ParseObject <User.User>(htmlString); listOut.Add(user); OnProcessParser(new ParserProcessEventArgs(listNickNames.Count(), listOut.Count)); } } } } catch (Exception e) { _logger.Exception(e); } return(listOut); }
void GetDataFromControls() { Element parentElement = null; HtmlSelector parentSelector = null; if (!parentTag.Key.Checked) { parentSelector = new HtmlSelector(parentSelectorTextBox.Text, SelectBy.CSS_SELECTOR); parentElement = new Element(parentSelector); } else { parentElement = new Element(parentSelector, parentTag.Value.Text); } HtmlSelector elementSelector; Element element = null; List <Field> fieldsList = new List <Field>(); for (int i = 0; i < tagsCheckBoxList.Count; i++) { if (fieldsTextBoxList.ElementAt(i).Text == "" || selectorsTextBoxList.ElementAt(i).Text == "") { continue; } elementSelector = new HtmlSelector(selectorsTextBoxList.ElementAt(i).Text, SelectBy.CSS_SELECTOR); if (!tagsCheckBoxList.ElementAt(i).Key.Checked) { element = new Element(elementSelector, AttributeType.TEXT); } else { element = new Element(elementSelector, tagsCheckBoxList.ElementAt(i).Value.Text); } fieldsList.Add(new Field(fieldsTextBoxList.ElementAt(i).Text, element)); } HtmlSelector Action = null; Element ActionElement = null; DomAction clickAction = new DomAction(DomAction.ActionType.CLICK, ""); IDictionary <Element, DomAction> siteActions = new Dictionary <Element, DomAction>(); IDictionary <Element, DomAction> pageActions = new Dictionary <Element, DomAction>(); for (int i = 0; i < actionsTextBoxList.Count; i++) { if (actionsTextBoxList.ElementAt(i).Text == "") { continue; } Action = new HtmlSelector(actionsTextBoxList.ElementAt(i).Text, SelectBy.CSS_SELECTOR); ActionElement = new Element(Action, AttributeType.TEXT); RadioButton radio = actionsRadioButtonsList.ElementAt(i).Controls.OfType <RadioButton>().FirstOrDefault(r => r.Checked); if (radio.Name.Equals("page")) { pageActions.Add(ActionElement, clickAction); } else { siteActions.Add(ActionElement, clickAction); } } siteDataModel = new DataModel(siteNameText.Text, parentElement, fieldsList, null, pageActions, siteActions); }