我是新来的硒。我的网站与IE的兼容性不佳,因此我决定尝试这种新技术,但是看不到我的代码出了什么问题。任何帮助将不胜感激。
Sub ExtractPrice()
Dim bot As WebDriver, myproducts As WebElements, myproduct As WebElement
Set bot = New WebDriver
bot.Start "chrome"
bot.Get "https://www.veadigital.com.ar/prod/72060/lechuga-capuchina-por-kg"
' Application.Wait Now + TimeValue("00:00:20")
Set myproducts = bot.FindElementsByClass("datos-producto-container")
'
For Each myproduct In myproducts
If myproduct.FindElementByClass("product-price").Text <> "" Then
'Debug.Print myproducts.FindElementByClass("product-price").Text
Worksheets("VEA").Range("b2").Value = myproducts.FindElementsByClass("product-price").Text
End If
Next
MsgBox ("complete")
End Sub
问题在这一行:
Worksheets("VEA").Range("b2").Value = myproducts.FindElementsByClass("product-price").Text
记住FindElements,返回一个webelements列表,而不是webelement。Instaead使用if条件中使用的行。
Worksheets("VEA").Range("b2").Value=myproduct.FindElementByClass("product-price").Text
Note :
使用上面的代码行,您会得到价格,但价格为379美元而不是3.79美元。由于没有。价格在页面上。更好的价格存储方式是:
Dim intValue = myproduct.FindElementByClass("product-price").Text
Dim decValue= myproduct.findElementByXPath(".//div[@class='product-price']//span").Text
Worksheets("VEA").Range("b2").Value = Replace(intValue , decValue, "."&decValue)
以上将分配$ 3.79。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句