【发布时间】: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
【问题讨论】:
-
在这里找不到这样的标签:view-source:amazon.com/dp/B00KTOE41I/?tag=stackoverfl08-20
-
你说得对,我更新了 ie.navigate url。标签应该在那里。