请教老师,当使用InvokeMember("Click") 模拟点击网页超链接,当碰到这种<a href='javascript:personmode(1)'>50</a>链接的时候,是不是要经过其他处理才能正常打开链接后的页面
以下的代码,碰到难题了
Dim tz As String = "5余0"
Dim web As System.Windows.Forms.WebBrowser = e.Form.Controls("WebBrowser1").basecontrol
web.Navigate("http://wap.pceggs.com/play/pc28.aspx")
Do Until web.ReadyState = 4
Application.DoEvents
Loop
Dim lis As System.Windows.Forms.HtmlElementCollection = web.Document.GetElementsByTagName("li") '获得当前页面的A标签HTML元素集合
Dim count As Integer = 0
For Each li As object In lis
If li.GetAttribute("ClassName") = "kj_white_line" Then
count += 1
If count = 5 Then
li.GetElementsByTagName("a")(0).InvokeMember("Click") '执行该标签的点击方法,实现
Do Until web.Document.Body IsNot Nothing AndAlso web.Document.Body.InnerHtml.Contains("自定义模式")
Application.DoEvents
Loop
'If web.Document.Body.InnerHtml.Contains("自定义模式")
'MessageBox.Show("包含")
'End If
Exit For
End If
End If
Next
Dim lis1 As System.Windows.Forms.HtmlElementCollection = web.Document.GetElementsByTagName("li") '获得当前页面li标签
Dim count1 As Integer = 0
For Each li1 As object In lis1
If li1.GetAttribute("ClassName") = "kj_white_line" Then
count1 += 1
If count1 = 4 Then
Dim ltc As System.Windows.Forms.HtmlElementCollection = li1.GetElementsByTagName("a") '获取该li内的所有a标签
For ii As Integer = 0 To ltc.count - 1
If ltc(ii).OuterHtml.contains("javascript:personmode") Then '如果a标签包含personmode个人模式这个字符串
If ltc(ii).InnerText.contains(tz) Then
ltc(ii).InvokeMember("Click") '执行该标签的点击方法
Exit For '终止循环
End If
End If
Next
Exit For
End If
End If
Next
[此贴子已经被作者于2016/3/15 22:28:41编辑过]