Link to home
Start Free TrialLog in
Avatar of gregman22
gregman22

asked on

Easy - Internet Question Page Source

I would like the code required to read the following page and place specific data into some text boxes.

Site: https://www.experts-exchange.com/viewMember.jsp?mid=1050957

I would like my Total Questions Asked to be in text1 and Total Answered To be in Text2.

I have previously asked a question on reading source, but I cannot understand how to do this.

thanks
Avatar of zzzzzooc
zzzzzooc

I've taken the time to do an example but no documentation. Since it's "easy" you should be able to understand it.

Include a reference to: "Microsoft HTML Object Library" .. You could additionally download the source and parse it for what you're looking for but I just did a simpler loop.


Private boolClose As Boolean
Private Sub Form_Load()
    Dim hDoc1 As New HTMLDocument, hDoc2 As New HTMLDocument
    Dim hColl As IHTMLElementCollection, hCell As HTMLTableCell
    Dim intWhich As Integer
    Me.Visible = True
    Set hDoc1 = hDoc2.createDocumentFromUrl("https://www.experts-exchange.com/viewMember.jsp?mid=1050957", "none")
    Do Until hDoc1.readyState = "complete"
        'This loop will repeat forever if it failed so:
        If boolClose = True Then Exit Sub
        DoEvents
    Loop
    Set hColl = hDoc1.All.tags("td")
    For Each hCell In hColl
        If intWhich = 1 Then
            Text1.Text = hCell.outerText
            intWhich = 0
        ElseIf intWhich = 2 Then
            Text2.Text = hCell.outerText
            intWhich = 0
        End If
        If hCell.outerText = "Questions Asked:" Then
            intWhich = 1
        ElseIf hCell.outerText = "Questions Answered:" Then
            intWhich = 2
        End If
    Next hCell
    Set hDoc1 = Nothing
    Set hDoc2 = Nothing
    Set hColl = Nothing
    Set hCell = Nothing
End Sub
Private Sub Form_Unload(Cancel As Integer)
    boolClose = True
End Sub
you could use a web browser control:

Private Sub Command1_Click()
WebBrowser1.Navigate2 "https://www.experts-exchange.com/viewMember.jsp?mid=1050957"
End Sub

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim Asked() As String, Answered() As String
Asked = Split(WebBrowser1.Document.body.innertext, "Questions Asked:")
Answered = Split(WebBrowser1.Document.body.innertext, "Questions Answered:")
Text1.Text = Left$(Asked(1), InStr(Asked(1), vbCrLf) - 1)
Text2.Text = Left$(Answered(1), InStr(Answered(1), vbCrLf) - 1)

End Sub
Avatar of gregman22

ASKER

zzzzzooc,

I pasted your code and put 2 text boxes on my form. I also referenced the library. I ran the program and nothing happened.

The text in the text box's did not change. Any ideas?
vinnyd79,

when i run your code i get the error "Subscript out of range" for Text1.Text = Left$(Asked(1), InStr(Asked(1), vbCrLf) - 1)

?
I really need help so points are increased.
The above example works fine for me. Did you modify anything?
No i didn't.

All I do is place the web browser control on my form and a command button.

It gave that error.
vinnyd79,

Sorry, It worked that time. (i'll give you points for that).

I really don't want to use the Web Browser Control. Is there another method you can come up with.

Points increased.

thanks
ASKER CERTIFIED SOLUTION
Avatar of vinnyd79
vinnyd79

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
vinnyd79,

works great.

I tried to get my total "questions opened" with the following, but it doesn't work?

Why?

If InStr(Ln, "Questions Opened:") > 0 Then
   Line Input #ff, Ln
   p = InStr(Ln, ">") + 1
   Qopen = Mid$(Ln, p, InStr(Ln, "</td>") - p)
   txtOpen.Text = Qopen
End If

I copied this between the other 2 If statements

thanks
What you had is fine except that on the page it is referred to as "Questions Open:" Not "Questions Opened:". So this should work:


If InStr(Ln, "Questions Open:") > 0 Then
  Line Input #ff, Ln
  p = InStr(Ln, ">") + 1
  Qopen = Mid$(Ln, p, InStr(Ln, "</td>") - p)
  txtOpen.Text = Qopen
End If