【问题标题】:Amazon Seller Fetch with VBA使用 VBA 获取亚马逊卖家
【发布时间】:2014-10-26 16:04:20
【问题描述】:

所以我一直在尝试用 VBA 编写一些东西来从任何亚马逊页面获取所有卖家名称和价格,这是一个产品列表示例:

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

我已经尝试了 VBA 中的每个选项来返回包含我想要的数据的某些标签的内部文本/内部 HTML,但是无论我使用什么方法都失败了。

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

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

这是我的代码,我知道它需要一个 for 循环来循环遍历指定标记的所有实例,但我什至无法让它返回内部文本。我尝试将变量调暗为“IHTMLElement”或“IHTMLElementCollection”但没有任何效果。

另外,我检查了 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://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

【问题讨论】:

标签: vba excel


【解决方案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")

除此之外,只会退回带有文字而非图片名称的卖家。


结果:


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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-23
    • 1970-01-01
    • 1970-01-01
    • 2012-09-23
    相关资源
    最近更新 更多