亚马逊卖家使用VBA获取

时间:2014-10-26 16:04:20

标签: excel vba excel-vba

因此,我一直试图在VBA中写一些东西来获取所有卖家的名字。来自任何亚马逊页面的价格,这里是产品列表示例:

http://www.amazon.com/gp/offer-listing/B00KTOE41I/ref=dp_olp_all_mbc?ie=UTF8&condition=all

我已经尝试过VBA中的每个选项来返回包含我想要的数据的某些标签的innertext / innerhtml,但无论我使用什么方法它都会失败。

getElementsByClassName - 错误, getElementsByName - 错误, getElementById - 错误 getElementsByTagName - 带回类似" [object HTMLSpanElement]"

卖家ID包含在此标记中: p class =" a-spacing-small olpSellerName" &安培;此标签中包含的价格:

这是我的代码,我知道它需要一个for循环来循环遍历指定标记的所有实例,但我甚至不能让它返回innertext。我已经尝试将变量称为" IHTMLElement"或者" IHTMLElementCollection"但没有任何作用。

另外,我有Microsoft HTML Object Library&互联网控制检查。

Option Explicit
Sub RunNewModule()

Dim ie As InternetExplorer
Dim html As HTMLDocument

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = False
ie.Navigate "http://www.amazon.com/gp/offer-listing/B00KTOE41I/ref=dp_olp_all_mbc?ie=UTF8&condition=all"

Do While ie.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop

Set html = ie.Document
Set ie = Nothing
Dim table
Dim sellers

UserForm1.TextBox2.Text = html.DocumentElement.innerHTML
Set table = html.getElementsByTagName("a").Item

sellers = table.all
UserForm1.TextBox7.Text = sellers

Cells.Clear
Range("A3").Value = "Seller"
Range("B3").Value = "Price"
Range("A4").Value = sellers

End Sub

1 个答案:

答案 0 :(得分:1)

使用以下网址: http://www.amazon.com/gp/offer-listing/B00KTOE41I/ref=dp_olp_all_mbc?ie=UTF8&condition=all

您可以像这样获取价格:Set priceData = html.getElementsByClassName("olpOfferPrice")

然后将它输出到B列:

cntr = 4
For Each Item In priceData
    Range("B" & cntr) = Item.innerText
    cntr = cntr + 1
Next Item

卖家也是如此:Set sellerData = html.getElementsByClassName("olpSellerName")

除此之外,只会返回带有文字名称而不是图像的卖家。


结果:

enter image description here


确保关闭IE(ie.Quit),否则将其保留在内存中。