C# - Get variable from webbrowser generated by javascript

寵の児 提交于 2019-12-25 04:03:54

问题


have downloaded page by webbrowser and need to get mail address. But it is generated by javastript. In code i can find this script:

<script type="text/javascript" charset="utf-8">var i='&#109;a'+'i&#108;'+'&#116;o';var a='impexta&#64;impexta&#46;sk';document.write('<a href="'+i+':'+a+'" onclick="_kt.i(386728, 20);">'+a+'</a>');</script>

I read everywhere how to Invoke script, by i don't know his name. So what i want is to get "a" variable value.

EDIT: Code before:

...
WebBrowser wb = new WebBrowser();
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);
wb.Navigate(url);

for (; wb.ReadyState != WebBrowserReadyState.Complete; )
{
    System.Windows.Forms.Application.DoEvents();
}
...

void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
        WebBrowser wb = sender as WebBrowser;
        if (wb != null)
        {
            if (wb.ReadyState == WebBrowserReadyState.Complete)
            {
                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.Load(wb.DocumentStream);
             }
        }
}

回答1:


I found easy solution. Just finding the right part of string in HTML code:

foreach (HtmlNode link in root.SelectNodes("//script"))
{
    if (link.InnerText.Contains("+a+"))
    {
        string[] strs = new string[] { "var a='", "';document.write" };
        strs = link.InnerText.Split(strs, StringSplitOptions.None);
        outMail = System.Net.WebUtility.HtmlDecode(strs[1]);
        if (outMail != "")
        {
            break;
        }
    }
}


来源:https://stackoverflow.com/questions/11242482/c-sharp-get-variable-from-webbrowser-generated-by-javascript

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