获取当前的web浏览器的URL或web浏览器的内容 [英] get current webbrowser url or webbrowser content

查看:177
本文介绍了获取当前的web浏览器的URL或web浏览器的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个登录按钮,并要检查,如果用户登录或没有。我虽然2种方法来做到这一点。


  1. 检查网页浏览器的网址是一个url相等的(如果用户成功登录的网址是为url1,如果没有该URL URL2)

  2. 检查当前web浏览器的内容所包含的单词(例如,如果用户登录成功,然后在重定向的页​​面都应该有谢谢你的消息)

我想提一提,所有的工作我唯一的问题是要检查,如果他登陆与否

 公共无效登录()
{
    webBrowser1.Document.GetElementById(用户名)的setAttribute(价值,txtUsername.Text)。
    webBrowser1.Document.GetElementById(密码)的setAttribute(价值,txtPassword.Text)。
    的foreach(在webBrowser1.Document.GetElementsByTagName的HtmlElement项目(输入))
    {
        如果(item.OuterHtml.Contains(input_submit))
        {
            item.InvokeMember(点击);
            打破; //这里的web浏览器重定向吧?
        }
    }
    如果(webBrowser1.Document.Body.InnerText.Contains(谢谢))
        CON = TRUE;
    其他
        CON = FALSE;
}


解决方案

我建议你使用的Htt prequest 以模拟登录进度,使用的Htt presponse ,以获取Web服务器响应和内容,并使用全球的的CookieContainer 以存储的cookie。

当你登录成功的消息,您可以使用其他的Htt prequest与globval的CookieContainer得到你想要下载或访问任何网页。

我希望这可以帮助你。

您可以使用的HttpWatch(www.httpwatch.com)看如何与WebServer.you Internet Explorer的数据交换也可以使用IE9 devloper工具来做到这一点(在IE9 preSS F12)。

I made a login button and want to check if the user logged in or not. I though 2 ways to do that.

  1. Check if the webbrowser url is equal with a url (If user login successfully the url is url1, and if not the url is url2)
  2. Check if the current webbrowser content contains a word (for example if user login successfully, then in the redirected page should have "Thank you" message)

I want to mention that all is working my only problem is to check if he logged in or not

public void Login()
{
    webBrowser1.Document.GetElementById("username").SetAttribute("value", txtUsername.Text);
    webBrowser1.Document.GetElementById("password").SetAttribute("value", txtPassword.Text);
    foreach (HtmlElement item in webBrowser1.Document.GetElementsByTagName("input"))
    {
        if (item.OuterHtml.Contains("input_submit"))
        {
            item.InvokeMember("Click");
            break; // Here the webbrowser redirect right?
        }
    }
    if (webBrowser1.Document.Body.InnerText.Contains("Thank you"))
        con = true;
    else
        con = false;
}

解决方案

I suggest you use HttpRequest to emulate the login progress,use HttpResponse to get webserver response and content and use global CookieContainer to store the cookies.

When you get login successful message,you can use other HttpRequest with globval CookieContainer to get any web pages you want download or access.

i hope this may help you.

you can use Httpwatch(www.httpwatch.com) to watch how Internet Explorer exchange data with WebServer.you can also use IE9 devloper tools to do this(press F12 in IE9).

这篇关于获取当前的web浏览器的URL或web浏览器的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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