已通过webbrowser下载页面并需要获取邮件地址。但它是由javastript生成的。在代码中我可以找到这个脚本:
<script type="text/javascript" charset="utf-8">var i='ma'+'il'+'to';var a='impexta@impexta.sk';document.write('<a href="'+i+':'+a+'" onclick="_kt.i(386728, 20);">'+a+'</a>');</script>
我到处都读到如何调用脚本,我不知道他的名字。所以我想要的是获得“变量”值。
编辑:之前的代码:
...
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);
}
}
}
答案 0 :(得分: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;
}
}
}