【发布时间】:2017-11-02 03:31:42
【问题描述】:
我正在尝试从 mcmaster.com 抓取标题和价格,以自动填充内部购买记录表。 (带有项目部件号的 URL 在下面被硬编码用于测试。)标题很好,但无法获得价格。我认为我的代码没有找到正确的位置,因为找不到该元素。我从here. 建模了我的代码
Sub get_title_header()
Dim wb As Object
Dim doc As Object
Dim sURL As String
Set wb = CreateObject("internetExplorer.Application")
sURL = "https://www.mcmaster.com/#95907A480"
wb.navigate sURL
wb.Visible = True
While wb.Busy Or wb.readyState <> READYSTATE_COMPLETE
DoEvents
Wend
'Wait a bit for everything to catchup...(network?)
Application.Wait (Now + TimeValue("0:00:02"))
'HTML document
Set doc = wb.document
Dim MyString As String
MyString = doc.Title
Sheet2.Cells(1, 2) = Trim(Replace(MyString, "McMaster-Carr -", "", , , vbTextCompare))
Dim el As Object
For Each el In doc.getElementsByName("Prce")
Sheet2.Cells(2, 2).Value = el.innerText
Next el
wb.Quit
End Sub
这个 iframe 是嵌套的吗?谁能解释为什么我的代码看不到 iframe 数据并帮助我获取商品价格?提前致谢!
【问题讨论】:
-
在您发送的链接中,您希望的价格是 6.42 美元吗?
-
$6.42 Each是价格元素的来源。
-
正确,寻找“每个 6.42 美元”