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);
             }
        }
}
3
  • So, is it loaded after the DOM? Commented Jun 28, 2012 at 10:34
  • I am not sure, so i added how i get the page string. Commented Jun 28, 2012 at 12:52
  • possible duplicate of Read Javascript variable from Web Browser control Commented Feb 10, 2015 at 16:10

1 Answer 1

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;
        }
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.