使用HTMLAgilityPack登录网站 [英] login to website using HTMLAgilityPack

查看:314
本文介绍了使用HTMLAgilityPack登录网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,我可以使用HTMLAgilitypack设置用户名和密码的值,但不能调用登录按钮的click事件(按钮的源代码中的ID为"s1").

In the below code, I can set the value of the username and password using the HTMLAgilitypack but I cannot invoke the click event of the login button (the id in the source code of the button is "s1").

反正有做这件事吗?我不使用WebBrowser的原因是因为我将需要HTMLAgilityPack从源代码中没有ID的页面中检索数据.

Is there anyway for this to be done? The reason I'm not using the WebBrowser is because I will need the HTMLAgilityPack to retrieve data from the page without IDs in the source code.

var doc = new HtmlWeb().Load("http://MYURL.com");
doc.DocumentNode.SelectSingleNode("name").SetAttributeValue("value", "MyUsername");
doc.DocumentNode.SelectSingleNode("password").SetAttributeValue("value", "MyPassword");

推荐答案

反正有这样做吗?

Is there anyway for this to be done?

与HTML Agility Pack(HAP)库提供的功能不完全相同-并非直接提供.

Not with what the HTML Agility Pack (HAP) library provides - not directly.

HAP非常适合获取单个页面并对其进行解析,但是它并不是为持续的交互而设计的. Cookie管理,JavaScript交互等功能缺失.

The HAP is great for getting a single page and parsing it, but it is not designed for continued interactions. Things that are missing are cookie management, JavaScript interaction and more.

要登录,您可能需要向服务器发送HTTP POST,包括所需的数据-HAP对此无能为力.

In order to login you probably need to send an HTTP POST to the server, including the data you want - the HAP can't help with that.

您将需要使用类似WebRequest的类进行发布-我建议您查看 fiddler 并使用它查看请求的外观并相应地构造请求,尽管这可能只是第一步.

You will need to use a class like WebRequest to make the post - I suggest looking at fiddler and using it to see what the request should look like and constructing it accordingly, though that may just be the first step.

您可能想研究网络自动化工具的使用,例如

You may want to investigate the use of web automation tools such as selenium or WatiN instead.

这篇关于使用HTMLAgilityPack登录网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆