WebBrowser1.Document.Body.(???)
I am trying to search through the HTML at a high level by using the WebBrowser control (rather than pulling a raw HTML from HTTP GET)
I have tried every iteration and exampleI can find including ..Body.InnetText, ...OuterText, ...ActiveElement.InnerText, ...outertext/HTM but I can't seem to find the following with any webBrowser1.Document.x call
All of the HTML that I am able to extract is missing the DIV tag
This is what I am looking for in the HTML stream:
Code:
<div class="buttonNext"><a href="main.php?g2_page=3"
title="Last"></a></div>
</td>
</tr></table>
</div>
Presense of the div tag with class of buttonNext indicates there is another page to be displayed and the absence of this text (no div with buttonNext) indicates we are looking at the last page in the batch.
Where to I find this in the document object model?
NOTE: The only way I can see this HTML is when I manually surf to the URL and select "View Source". Only at this point do I see this tag that seems to be missing from all the document object calls I have attempted.
Re: WebBrowser1.Document.Body.(???)
Quote:
NOTE: The only way I can see this HTML is when I manually surf to the URL and select "View Source". Only at this point do I see this tag that seems to be missing from all the document object calls I have attempted.
this would indicate to me that possibly it is in a frame or iframe
Re: WebBrowser1.Document.Body.(???)
Photo of firebug display
This is both the HTML and the DOM from a firebug display of them both. You can download the photo to get a better resolution here.
The search for "buttonNext" is what opened the HTML tree view to show all the occurrences of the DIV tag with a class of buttonNext (class=buttonNext signals there are additional pages).
Note that the buttonNext is only found in the HTML stream and is not seen anywhere in the DOM part of firebug on the right of the referenced photo.
Re: WebBrowser1.Document.Body.(???)
the photos do not help at all
have you looked to see if the button is contained in a frame within the document?
Re: WebBrowser1.Document.Body.(???)
Well after 3 days I am starting to think that even if there is an answer (where I find a way to locate my simple <div class="buttonNext" in the mass of a mass of a DOM tree that I must iterate through to find this), yes even if there is an answer to where I can find what I am looking for in the DOM, the bigger question is why bother? When I consider that there are very, very few examples of reading from the DOM with VB6 that I can find online and when I consider that most of the examples are writing to the DOM (i.e. controlling the page by entering text and pushing buttons, maybe I am wasting my time and need to simply use something like this:
Code:
Private Sub Command1_Click()
Dim strPage, strISBN, strURL As String
On Error Resume Next
' set the proper URL to Amazon.Com asking for specific book
strISBN = "1558605037" ' ISBN for the WFbook
strURL = "http://www.amazon.com/exec/obidos/ASIN/" & strISBN & "/"
' get the webpage content using Inet control
strPage = Inet1.OpenURL(strURL, icString)
' put the ranking value into the textbox
Text1.Text = GetRank(strPage, "Sales Rank: </b>", "</font>")
End Sub
Private Function GetRank(strPage, strPrePat, strPostPat As String) As String
Dim iStart, iEnd As Integer
Dim strIn, strOut As String
GetRank = ""
iStart = InStr(1, strPage, strPrePat) ' find first pattern
If iStart <> 0 Then
iStart = iStart + Len(strPrePat)
iEnd = InStr(iStart, strPage, strPostPat) ' second
If iEnd <> 0 Then
strIn = Mid(strPage, iStart, iEnd - iStart)
strOut = ""
For iStart = 1 To Len(strIn) ' strip out control chars
If Mid(strIn, iStart, 1) < " " Then
strOut = strOut & " " ' add a blank instead
Else
strOut = strOut & Mid(strIn, iStart, 1)
End If
Next iStart
GetRank = Trim(strOut) ' return extracted value
End If
End If
End Function
Then use my own code to simply search and parse the return HTML string of the entire page and just forget the DOM all together. When I need to go to a link, I'll just pull the HTML of the second page I am looking for through the same method.
Re: WebBrowser1.Document.Body.(???)
Oh no, the above call returns a blank string. Back to the drawing board.
Re: WebBrowser1.Document.Body.(???)
Problem solved! When I am the fool, I hope to admit it. I missed the fact that when I called Webbrowser control the screen it was looking at was a screen where I had not logged into the facility yet and thus did not have the DIV tag because before you log in, there actually is no "next" tag. Pretty stupid all right but at least I only wasted 3 days debugging it /LOL !! Sorry to have burned you all with my ignorance on this one but I really appreciate your trying to help. All is indeed well in the land of DOM.
Re: WebBrowser1.Document.Body.(???)
So here is the HTML in the document that I am looking for:
Code:
<TABLE cellSpacing=0 cellPadding=0>
<TBODY>
<TR>
<TD> </TD>
<TD><div class="buttonNext"><a href="/main.php?g2_page=2" title="Next"></a></div></td>
<td><div class="buttonLast"><a href="/main.php?g2_page=3" title="Last"></a></div></td>
</TR>
</TBODY>
</TABLE>
Assumptions (for VB6, Win 7 64bit implementation):
Code:
(Project:)
Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\Windows\SysWow64\stdole2.tlb#OLE Automation
Object={EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}#1.1#0; ieframe.dll
Reference=*\G{3050F1C5-98B5-11CF-BB82-00AA00BDCE0B}#4.0#0#C:\Windows\SysWow64\MSHTML.TLB#Microsoft HTML Object Library
Object={831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0; mscomctl.ocx
(Form:)
Object = "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}#1.1#0"; "SHDOCVW.DLL"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
The way I find it is via this loop:
Code:
Dim HTMLDoc As HTMLDocument
Dim HTMLlinks As HTMLAnchorElement
Dim STRtxt As String
On Error Resume Next
Set HTMLDoc = WebBrowser1.Document
For Each HTMLlinks In HTMLDoc.links
If HTMLlinks.getAttribute("title") = "Next" Then
MsgBox "To go to the next page, navigate to: " & HTMLlinks.href
End If
DoEvents
Next HTMLlinks
Which results:
To go to the next page, navigate to: http://mydomain.com/main.php?g2_page=2
I hope this helps someone else who may be searching for Div tags and links in a future project. Enjoy!
Re: WebBrowser1.Document.Body.(???)
i would have done something like
vb Code:
for each ele in wb.document.getelementsbytagname("a")
if ele.title = "Next" then ele.click: exit for
next
where wb is webbrowser, not tested