excel vba抓取网页数据(Papir怎么做才能将数据分成不同的列?非常感谢您的帮助!)

优采云 发布时间: 2022-03-01 03:06

  excel vba抓取网页数据(Papir怎么做才能将数据分成不同的列?非常感谢您的帮助!)

  我正在尝试从网页中获取一些数据并且取得了部分成功。但我对 html 和 javascript 的了解并不是最好的。我可以抓取数据并将其填充到工作表中,但如果可能的话,我想进一步分离数据。

  这是我的代码:

  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

  现在,在网页上,html源代码(摘录)如下:

  

Papir ubleket kraft 60g 40cm 5kg/rull

Varenr : 491215

  我只希望文本“Papir ubleket kraft paper 60g 40cm 5kg/rull”显示在 Excel 工作表中,但我也得到“Varenr:491215”。其他列也是如此。我试图发布一张excel snatch的图片,并没有被拒绝。您可以运行代码并查看,或者我可以通过电子邮件将屏幕截图发送给您。

  我该怎么做才能将数据分成不同的列?

  谢谢您的帮助!:-)

0 个评论

要回复文章请先登录注册


官方客服QQ群

微信人工客服

QQ人工客服


线