0

已通过网络浏览器下载页面,需要获取邮件地址。但它是由javastript生成的。在代码中我可以找到这个脚本:

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

我到处阅读如何调用脚本,我不知道他的名字。所以我想要的是获得“a”变量值。

编辑:之前的代码:

...
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);
             }
        }
}
4

1 回答 1

1

我找到了简单的解决方案。只需在 HTML 代码中找到字符串的正确部分:

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;
        }
    }
}
于 2012-07-03T19:31:46.970 回答