如何以编程方式浏览页面?

发布于 2024-12-20 05:02:36 字数 423 浏览 1 评论 0原文

我见过很多关于如何获取 URI 内容的示例。我也经常使用 HTMLAgilityPack。 我想要的是为asp网站创建单元测试环境。

我看过 BrowserSession这个问题但是,尽管过程看起来不错,但他们不要登录网站。我尝试了很多知名网站。

关于如何浏览代码有什么想法吗?

I've seen numerous examples on how to get the contents of a URI. I also used HTMLAgilityPack a lot.
What I want is to create Unit Testing environment for asp websites.

I've seen the BrowserSession and this Question but although, the process seems fine, they do not login in a website. I tried numerous well-known websites.

Any ideas on how to browse though code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

东风软 2024-12-27 05:02:36

听起来您想在网页上提交表单并查看结果页面的响应 HTML。

此方法将采用表单目标 URL 并使用 parms 字典中给定的命名参数提交帖子。

我使用下面的方法在网页上进行密码验证并查看验证后的响应。您需要知道目标 URL 以及您希望在请求中传递的表单字段。

private string SubmitRequest(string url, Dictionary<string, string> parms)
{
    var req = WebRequest.Create(url);
    req.Method = "POST";

    string parmsString = string.Join("&", parms.Select(p => string.Format("{0}={1}", p.Key, p.Value)));
    req.ContentLength = parmsString.Length;

    using (StreamWriter writer = new StreamWriter(req.GetRequestStream()))
    {
        writer.Write(parmsString);
        writer.Close();
    }

    var res = req.GetResponse();

    using (StreamReader reader = new StreamReader(res.GetResponseStream()))
    {
        string response = reader.ReadToEnd();
        reader.Close();
        return response;
    }
}

如果您想要更具体的东西,或者这不是您想要的,请发表评论。

It sounds like you want to submit a form on a web page and view the response HTML back of the resulting page.

This method will take a form target URL and submit a post with the given named arguments in the parms Dictionary.

I have used the method below to perform password authentication on a web page and view the response after authentication. You will need to know the target Url and the form fields you wish to pass in the request.

private string SubmitRequest(string url, Dictionary<string, string> parms)
{
    var req = WebRequest.Create(url);
    req.Method = "POST";

    string parmsString = string.Join("&", parms.Select(p => string.Format("{0}={1}", p.Key, p.Value)));
    req.ContentLength = parmsString.Length;

    using (StreamWriter writer = new StreamWriter(req.GetRequestStream()))
    {
        writer.Write(parmsString);
        writer.Close();
    }

    var res = req.GetResponse();

    using (StreamReader reader = new StreamReader(res.GetResponseStream()))
    {
        string response = reader.ReadToEnd();
        reader.Close();
        return response;
    }
}

If there is something more specific you are wanting or this is not what you are looking for then please post a comment.

千纸鹤带着心事 2024-12-27 05:02:36

我的建议是尝试一些 WebDriverJs 教程,看看是否适合您。它主要用于测试,但也可用于其他目的。我正在使用它来自动响应购物平台上的用户查询。

My suggestion is to try some tutorials of WebDriverJs and see if that works for you. It is mainly used for testing but can also be used for other purposes. I am using it to automate responding to user's queries on a shopping platform.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文