【发布时间】:2020-12-16 09:06:23
【问题描述】:
我是使用硒的新手。我有一个与 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被硬编码为 b2? - 当您完成循环时,您将永远写入该单元格...除此之外,您需要描述正在发生的事情以及您期望发生的事情,并提供足够的支持信息,以便我们了解您的问题。 -
Rich 先生,它假设如果它有效,它应该给我价格(这就是我需要的),它属于“产品价格”类,但它没有。我只想要这个元素,但如果问题是“b2”,它应该在调试时带来它,而且它什么也没给我带来
-
@rahul rai,没有错误,只是没有带来任何数据
-
似乎是同步问题。您需要在交互元素之前提供一些明确的等待。
Set myproducts = bot.FindElementsByClass("datos-producto-container")
标签: vba selenium selenium-webdriver web-scraping