问题描述
我对以下简单代码有疑问。我有一个循环 通过xxx.pl页上的span标签。在搜索过程中 第二个循环我必须导航到第三个循环中的另一个URL(在同一服务器和相同目录上)xxx.pl/yyy,并返回到先前的URLxxx.pl。之后,我在这里出错了
if (el.GetAttribute("className") == "account-block-subtext")
行。
错误信息是:
System.UnauthorizedAccessException
HResult=0x80070005
Message=Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
Source=System.Windows.Forms
有什么建议吗?在我看来,某些操作会更改el对象,因此退出第三个循环后我将无法访问它。 Maby会话数据丢失了吗?代码如下:
foreach (HtmlElement el in doc.GetElementsByTagName("span"))
{
if (el.GetAttribute("className") == "account-block-subtext")
{
foreach (HtmlElement elchild in el.Children)
{
if (elchild.TagName == "A")
{
string alink = "";
try { alink = elchild.GetAttribute("href"); } catch { alink = ""; }
if (alink.Contains("/user/bbb.PHP"))
{
// klik alink
elchild.InvokeMember("Click");
webbrowser1.Navigate("xxx.pl/yyy");
while (webbrowser1.ReadyState != WebbrowserReadyState.Complete)
{
System.Windows.Forms.Application.DoEvents();
System.Threading.Thread.Sleep(500);
}
//Debug.WriteLine(webbrowser1.Url.AbsoluteUri);
foreach (HtmlElement cashmail in doc.GetElementsByTagName("span"))
{
// Debug.WriteLine(">" + cashmail.GetAttribute("className"));
if (cashmail.GetAttribute("className") == "to_read")
{
Debug.WriteLine("cashmail");
}
}
//doc = doc_temp;
}
if (alink.Contains("/shops/pppp.PHP"))
{
// klik alink
Debug.WriteLine(alink);
}
alink = "";
}
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)