无法在 Iframe div 内的元素上获取 ID
Can't pickup id on element inside of div of Iframe
使用此 Html... 来自 http://www.ebay.com/itm/261901470624?ssPageName=STRK:MESELX:IT&_trksid=p3984.m1558.l2649
<div id="ds_div">
Yada Yada Yada.
</div>
我尝试过使用这两种方法捕获它...
方法一(给了我一个空异常)
TextBoxDetails.Text = WebBrowser1.Document.GetElementById("ds_div").InnerText
方法二(无错误,无输出)
Dim PageElement3 As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("div")
For Each CurElement As HtmlElement In PageElement3
If (CurElement.GetAttribute("id") = "ds_div") Then
TextBoxDetails.Text = CurElement.GetAttribute("InnerText")
End If
Next
还有什么我可以尝试的?
据我所见,没有这样的"ds_div"元素,可能是动态创建的,但这段代码无一例外地工作:
Dim elementId As String = "ds_div"
Dim PageElement3 As HtmlElement = WebBrowser1.Document.GetElementById(elementId)
Dim i As Integer = 0
If Not PageElement3 Is Nothing Then
TextBoxDetails.Text = PageElement3.InnerHtml
Else
MsgBox("No such element " & elementId & "!")
End If
尝试使用 "itemInfoLabel" 或 "vi-cdown_timeLeft"
等 ID
这就是我如何让它工作的。我捕获了 iframe 的源,并将其发送到我设置为隐藏的另一个浏览器,然后在文档完成后,我能够检索到我需要的项目。
在我的 "Aquire Data" 按钮下我有这个代码...
'Get Item Details
Dim myFrames As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("iframe")
For Each el As HtmlElement In myFrames
If el.GetAttribute("id") = "desc_ifr" Then
WebBrowser2.Navigate(el.GetAttribute("src"))
End If
Next
作为我的事件处理程序,我有这段代码...
Private Sub WebBrowser2_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser2.DocumentCompleted
If Not WebBrowser2.Document Is Nothing Then
TextBoxDetails.Text = WebBrowser2.Document.GetElementById("ds_div").InnerText
End If
End Sub
使用此 Html... 来自 http://www.ebay.com/itm/261901470624?ssPageName=STRK:MESELX:IT&_trksid=p3984.m1558.l2649
<div id="ds_div">
Yada Yada Yada.
</div>
我尝试过使用这两种方法捕获它...
方法一(给了我一个空异常)
TextBoxDetails.Text = WebBrowser1.Document.GetElementById("ds_div").InnerText
方法二(无错误,无输出)
Dim PageElement3 As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("div")
For Each CurElement As HtmlElement In PageElement3
If (CurElement.GetAttribute("id") = "ds_div") Then
TextBoxDetails.Text = CurElement.GetAttribute("InnerText")
End If
Next
还有什么我可以尝试的?
据我所见,没有这样的"ds_div"元素,可能是动态创建的,但这段代码无一例外地工作:
Dim elementId As String = "ds_div"
Dim PageElement3 As HtmlElement = WebBrowser1.Document.GetElementById(elementId)
Dim i As Integer = 0
If Not PageElement3 Is Nothing Then
TextBoxDetails.Text = PageElement3.InnerHtml
Else
MsgBox("No such element " & elementId & "!")
End If
尝试使用 "itemInfoLabel" 或 "vi-cdown_timeLeft"
等 ID这就是我如何让它工作的。我捕获了 iframe 的源,并将其发送到我设置为隐藏的另一个浏览器,然后在文档完成后,我能够检索到我需要的项目。
在我的 "Aquire Data" 按钮下我有这个代码...
'Get Item Details
Dim myFrames As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("iframe")
For Each el As HtmlElement In myFrames
If el.GetAttribute("id") = "desc_ifr" Then
WebBrowser2.Navigate(el.GetAttribute("src"))
End If
Next
作为我的事件处理程序,我有这段代码...
Private Sub WebBrowser2_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser2.DocumentCompleted
If Not WebBrowser2.Document Is Nothing Then
TextBoxDetails.Text = WebBrowser2.Document.GetElementById("ds_div").InnerText
End If
End Sub