VBA problem to get innertext from website

robwik87

New Member
Joined
Dec 9, 2015
Messages
1
Hi all!

I have a problem that I have tried to figure out a long time now.
I need to get information from a website and paste it in the a2 cell on sheet3.
but I cant get it to work I have tried many different codes but I am stuck.

the code I have is:

Sub test2()

'klicka på en knapp utan namn
Dim IE As Object
Dim IEdoc As Object

Set IE = CreateObject("internetExplorer.Application")



With IE
.Visible = True
.navigate ("http://www.allabolag.se")
End With
While IE.readyState <> 4
Set xobj = objIe.document.getElementById("myDiv")
Set xobj = xobj.getElementsByClassName("myTable").Item(0)
Set xobj = xobj.getElementsByClassName("data")(0)

Debug.Print xobj.innerText
setxboj = Nothing

DoEvents
Wend

IE.document.getElementsByName("what").Item.innerText = ThisWorkbook.Sheets("blad2").Range("a2").Value

Set allInputs = IE.document.getElementsByTagName("input")
For Each element In allInputs
If element.getAttribute("src") = "/img/button_sok_56x25.png" Then
element.Click
Exit For
End If
Next element



'ID = Printtitel
Do While IE.Busy: DoEvents: Loop

Set sht = Sheets("Blad3")
RowCount = 1
sht.Range("a" & RowCount) = "Moderbolag:"


´missing code string



Set IE = Nothing
'ThisWorkbook.Sheets("blad3").Range("a2") = IE.document.getelementsbyid("Printtitel")
End Sub

The inner text that I trying to get is in the code:

HTML lang=SV XMLNS="Http://www.w3.org/199/xhtml
"< head >....< /head >"
"< body >"
then its 9 div strings
one table
then tbody in table
the second "< tr >"
in the "< td >" you have a "< h1 >" and ID is "printTitle"
and its the innertext of that Id I need!

im doing something wrong but I don't know what it is.
kind of new to extracting text from websites.

hope to find help here!

/ Robin
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Robin

This part of the code should not be in the first loop.
Code:
Set xobj = IE.document.getElementById("myDiv")
Set xobj = xobj.getElementsByClassName("myTable").Item(0)
Set xobj = xobj.getElementsByClassName("data")(0)

Debug.Print xobj.innerText
setxboj = Nothing
It should go after the loop.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,054
Latest member
juliecooper255

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top