Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I basically want to be able to read the players rank using VBA in Excel but haven't been able to get it working. I get a value error and can't figure out why. I only have a very basic knowledge of VBA so please be patient.

So I've changed the code to whats shown down below but when run in excel it returns a value of 0. Nevermind worked when I restarted excel. Thanks for all the help!

    Function player_battlerank(player_name As String)
start1:
Set objhttp1 = New WinHttp.WinHttpRequest
Dim doc1 As MSHTML.HTMLDocument
objhttp1.Open "GET", "http://ps2.fisu.pw/player/?name=" & player_name, True
objhttp1.send

objhttp1.waitforresponse

If objhttp1.status <> 200 Then GoTo start1
Set doc1 = New MSHTML.HTMLDocument
doc1.body.innerHTML = objhttp1.responseText

Set obj1 = doc1.getelementbyid("stat_overview")
For Each obj3 In obj1.getelementsbytagname("div")
    If obj3.innerText Like "*BATTLE RANK*" Then
        player_battlerank = obj3.getelementsbytagname("b")(0).innerText
        Exit Function
    End If
Next obj3
End Function
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
290 views
Welcome To Ask or Share your Answers For Others

1 Answer

Something like this should work:

'....
Set doc1 = New MSHTML.HTMLDocument
doc1.body.innerHTML = objhttp1.responseText

Set obj1 = doc1.getelementbyid("stat_overview")
For Each obj3 In obj1.getelementsbytagname("div")
    If obj3.innerText Like "*BATTLE RANK*" Then
        player_rank = obj3.getelementsbytagname("b")(0).innerText
        Exit Function
    End If
Next obj3
'....

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...