0

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);
             }
        }
}
prespic
  • 1,635
  • 1
  • 17
  • 20

1 Answers1

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;
        }
    }
}
prespic
  • 1,635
  • 1
  • 17
  • 20
  • Sorry, but creating separate HTML element with serialized content for getting variable... it's awful. Better to use native abilities: `var window = WebBrowser.Document.parentWindow; return window.GetType().InvokeMember(propertyName, BindingFlags.GetProperty, null, window, null);` – RReverser Dec 05 '12 at 21:05