How to InvokeMember using HtmlAgilityPack

寵の児 提交于 2020-01-16 04:12:12

问题


I want to use HtmlAgilityPack class to login. But I don't know how.

This is what I've tried. But it's not working.

txtUserName.Text = "username";
txtPassword.Text = "password";
HtmlAgilityPack.HtmlDocument doc = new HtmlWeb().Load("about:Tabs");
doc.GetElementbyId("username").SetAttributeValue("value", txtUserName.Text);
doc.GetElementbyId("password").SetAttributeValue("value", txtPassword.Text);
foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//button[@class='btn login-btn blue pull-right btn-primary']"))
 {
    node[0].InvokeMember("click");//wrong code
 }

I cannot use WebBrowser class.


回答1:


I found a way to login using Selenium and I think it's the best way to do it:

IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("Your Address Login");
IWebElement query = driver.FindElement(By.Id("username"));
query.SendKeys("Your Username");
query = driver.FindElement(By.Id("password"));
query.SendKeys("Your Password");
query.Submit();

download selenium for dotnet

After download add reference WebDriver.dll and use namespace OpenQA.Selenium.Firefox;

Learn more Here




回答2:


HtmlAgilityPack can only parse html.

Use WebClient instead.



来源:https://stackoverflow.com/questions/34242048/how-to-invokemember-using-htmlagilitypack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!