I am trying to grab some data from a webpage and am partialy successful. However my html and javascript knowledge is not at its best. I can grab data and populate in my sheet, but i want to seperate the data more if possible.
Here's my code:
Sub get_data_2()
'Source for this code is:
'http://stackoverflow.com/questions/26613043/get-data-out-of-a-webpage-with-vba
Dim sht As Worksheet
Dim SKU As String
Dim RowCount As Long
Set sht = Sheet8
Set ie = CreateObject("InternetExplorer.application")
RowCount = 1
'This just gives the columns a titel i row numer 1.
sht.Range("a" & RowCount) = "SKU"
sht.Range("b" & RowCount) = "Own titel"
sht.Range("c" & RowCount) = "EMO titel"
sht.Range("d" & RowCount) = "Product info"
sht.Range("e" & RowCount) = "Weight"
sht.Range("f" & RowCount) = "Volum"
sht.Range("g" & RowCount) = "EAN"
sht.Range("h" & RowCount) = "Originalnumber"
sht.Range("i" & RowCount) = "Price"
sht.Range("j" & RowCount) = "Stock"
sht.Range("k" & RowCount) = "Units"
Do
RowCount = RowCount + 1
SKU = sht.Range("a" & RowCount).Value ' **SKU is 491215 in this example**
With ie
.Visible = False
.navigate "https://www.emo.no/web/ePortal/ctrl?action=showiteminfo&itemNo=" & SKU
Do While .Busy Or _
.readyState <> 4
DoEvents
Loop
sht.Range("c" & RowCount).Value = .document.getElementById("itemDetail_heading").innerText
sht.Range("d" & RowCount).Value = .document.getElementById("itemDetail_textBox").innerText
sht.Range("e" & RowCount).Value = .document.getElementById("itemDetail_technicalDataBox").innerText
sht.Range("j" & RowCount).Value = .document.getElementById("itemDetail_deliveryBox").innerText
sht.Range("k" & RowCount).Value = .document.getElementById("itemDetail_unitsbox").innerText
End With
Loop While sht.Range("a" & RowCount + 1).Value <> ""
Set ie = Nothing
End Sub
Now, on the webpage the html source (an extract) is as follows:
<div id="itemDetail_container">
<div id="itemDetail_heading">
<div class="xxLarge extraBold">Papir ubleket kraft 60g 40cm 5kg/rull</div>
<div class="item_itemNumberBox">
<span class="darkGray medium">Varenr : 491215</span>
</div>
</div>
I want only for the text " Papir ubleket kraft 60g 40cm 5kg/rull " to appear in my excel sheet, but I get "Varenr : 491215" as well. The same goes for the other colums. I tried to post apicture of thge excel grab, but was not alowed to. You can run the code and see, or i can you e-mail you the screenshot.
What can I do to get the data into different columns?
Many thanks for your help! :-)