Data from web page

S

spaceman33

I am trying to get some data from a web site.

Because the data is part of a table on a web site, not the main table, I
think that's why I can't find it.

Code similar to what I am trying is:

a = ""
url = link
Dim IE As Object
'this part open explorer and navigates to the web site I want
Set IE = CreateObject("internetexplorer.application")
With IE
.Visible = False
.navigate url
Do While .ReadyState <> 4: Loop
a = .document.body.innertext
End With
'I would then search for the text preceeding the value I am looking for
Position = InStr(1, a, "Enemy Kills:", vbTextCompare)


Like I said, I think because the text is in another section of the web page
it doesn't find it.

Some data I found from the Source of the web site is:

<table id="member-jacket" class="info info-member" cellspacing="1">

I am hoping this will help find the solution.

Thanks in advance for any thoughts.
 
G

Guest

I'm not exactly sure of your intention or usage, but if it is just to
retrieve some data from a web page and display it in some range on a
worksheet then the following code should do the trick ...

--------------------
Sub Create_Web_QueryTables()
Dim strCnn As String
' Insert the full URL desired. For example as below ...
strCnn =
"URL;http://investing.reuters.co.uk/Stocks/Quote.aspx?symbol=RTR.L"
With ActiveSheet.QueryTables.Add(Connection:=strCnn,
Destination:=Range("A1"))
.Name = "WebQueryTest"
.QueryType = xlWebQuery ' Based on a Web page
.RefreshStyle = xlInsertEntireRows
.HasAutoFormat = False
.WebFormatting = xlWebFormattingNone
' We want to specify particular tables, otherwise could use
xlAllTables (default)
.WebSelectionType = xlSpecifiedTables
' Define the tables on this page to import
.WebTables = "25"
.RefreshOnFileOpen = True
.Refresh
End With
End Sub
 
G

Guest

Sorry, got a bit tangled up with my copy/paste and pressed the post button
too quickly.

The line of code after ".Name = ..." is just a comment and should read as
follows ...

' Based on a web page: .QueryType = xlWebQuery.

Apologies, Sean.
 
S

spaceman 33

Thanks for the info.

I found the code I had previously used:
=========================================================
Sub Button4_Click()
'AA
a = ""
url = "http://login.americasarmy.com/views/login.php"
'Const url As String = link
Dim IE As Object
Set IE = CreateObject("internetexplorer.application")
With IE
.Visible = True
.navigate url
Do While .ReadyState <> 4: Loop
a = .document.body.innertext
End With
'enter login details
IE.document.all("username").Value = "username"
IE.document.all("password").Value = "password"
With IE.document.Forms(0)
.submit.Click
End With
'get score

#####THIS NEXT PART IS WHERE I WANT TO DO THE SEARCHING FOR THE STRING
Experience Required for Next Level#####

Position = InStr(1, a, "Experience Required for Next Level",
vbTextCompare)
honour = ""
For z = 13 To 25
If Asc(Mid$(a, Position + z, 1)) = 13 Then z = 25: GoTo 599
honour = honour & Mid$(a, Position + z, 1)
599
Next z
MsgBox honour
Set IE = Nothing
End Sub
==========================================================

How would I put that code into the above? I am already at the web site
page I want to grab the information from, I just need to get the
information from a section of the web page (different table or whatever
it is).

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top