我正在尝试从网页中抓取数据,我需要 4 位数据,其中 2 位我已经能够检索到,但另外 2 位暗示了我。
这不是一个固定的 URL,但在重定向后已从 IE 检索此 URL,因此对于本示例,我将使用: https://cpc.farnell.com/warton/microprint-p2010-15-32um-250g/solder-paste-15-32um-250g-pot/dp/SD02808
我希望获得称号:
Microprint P2010 免清洗、无铅焊膏,15-32um,250g 罐 - MICROPRINT P2010 15-32UM,250G
和制造商部件号
缩微打印 P2010 15-32UM,250G
我一直在使用 getElementbyID 来获取产品概述/产品信息,效果很好,但其他文本字段似乎不起作用(我查看了 Xpath,它在 Object 上出错) VBE 中需要)
我使用以下方法成功实现了另外 2 个元素:
Sub Mani()
'Declare variables
Dim objWeb As Object
Dim objHTML As Object
Dim objElement As Object
Dim strData, StrData1 As String
Set objWeb = CreateObject("internetexplorer.Application")
str = "https://cpc.farnell.com/"
objWeb.navigate str & Cells(1, 1).Value
While objWeb.Busy = True
Wend
FullURL = objWeb.LocationURL
Range("b2").Value = FullURL
objWeb.navigate FullURL
'IE.Visible = True
While objWeb.Busy = True
Wend
Set objHTML = objWeb.document
strData = objHTML.getElementById("pdpSection_FAndB").innerText
ActiveSheet.Range("C3").Value = strData
strData = objHTML.getElementById("pdpSection_pdpProdDetails").innerText
Set strData = Nothing
ActiveSheet.Range("D3").Value = strData
objWeb.Quit
End Sub
URL 重新加载是为了围绕 URL 重定向进行导航,
https://cpc.farnell.com/SD02808
重定向到主网址
https://cpc.farnell.com/warton/microprint-p2010-15-32um-250g/solder-paste-15-32um-250g-pot/dp/SD02808
我想将零件号输入到 A1 中,Excel 将其用作 VB 中的变量,然后从 IE 实例中重新读取完整的 url。 这是尝试使用从 Web 获取数据时遗留下来的问题,由于页面脚本错误,该功能效果不佳,因此使用了 IE 实例。
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号