亚马逊卖家使用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]”

卖家编号包含在此标签内:p class =“a-spacing-small olpSellerName”&包含在此标签内的价格:

这里是我的代码,我知道它需要一个for循环来遍历指定标签的所有实例,但我甚至不能得到它返回的innertext。 我试着将variables作为“IHTMLElement”或“IHTMLElementCollection”来debugging,但没有任何效果。

此外,我有Microsoft HTML对象库和Internet控制检查。

Option Explicit Sub RunNewModule() Dim ie As InternetExplorer Dim html As HTMLDocument Set ie = CreateObject("InternetExplorer.Application") ie.Visible = False ie.Navigate "http://rads.stackoverflow.com/amzn/click/B00KTOE41I" 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 

使用此url: 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")

除了这只会返回卖家的名字在文字而不是图像。


结果:

在这里输入图像说明


确保closuresIE( ie.Quit ),否则将其保存在内存中。