如何使用VBA将eBay网站上的“售出数量”导入excel?

时间:2019-05-28 15:05:18

标签: html excel vba web-scraping

我正在尝试使用VBA将eBay的已售商品数量(实时)导入excel? 到目前为止,这是我在stackoverflow上发现的。 但是我没有任何结果 我将不胜感激任何帮助 谢谢

Option Explicit
Sub readData()

Dim XMLPage As New MSXML2.XMLHTTP60
Dim html As New MSHTML.HTMLDocument
Dim profile As IHTMLElement6

XMLPage.Open "GET", "https://www.ebay.com/itm/VIRGINIA-CAVALIERS-FINAL-FOUR-National-FREAKIN-Champions-T-Shirt-Gildan/352639122861", False
XMLPage.send

If XMLPage.Status <> 200 Then MsgBox XMLPage.statusText
html.body.innerHTML = XMLPage.responseText


 For Each profile In html.getElementsByTagName("span")(0).Children
 Debug.Print profile.getElementsByClassName("vi-txt-underline")(0)

Next

End Sub

1 个答案:

答案 0 :(得分:0)

使用该类很好。页面上只有1个匹配项,因此无需获取多个集合并循环。只需使用querySelector返回第一个匹配项即可。

Public Sub GetNumberSold()
    Dim html As HTMLDocument

    Set html = New HTMLDocument

    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", "https://www.ebay.com/itm/VIRGINIA-CAVALIERS-FINAL-FOUR-National-FREAKIN-Champions-T-Shirt-Gildan/352639122861", False
        .send
        html.body.innerHTML = .responseText
    End With

    MsgBox html.querySelector(".vi-txt-underline").innerText
    Debug.Print Replace$(html.querySelector(".vi-txt-underline").innerText," sold",vbNullString)
    Debug.Print split(html.querySelector(".vi-txt-underline").innerText,chr$(32))(0)

End Sub