我正在尝试从className获取数据。我收到了错误
运行时错误' 438'对象不支持此属性或方法
但我能成功从ID获取数据。请帮忙。
以下是我尝试的代码。
Sub Use_Cell_text()
Dim driver As New FirefoxDriver
driver.Get "https://www.99acres.com/2-bhk-bedroom-apartment-flat-for-sale-in-jaypee-greens-kosmos-sector-134-noida-942-sq-ft-r1-spid-E31025131?pos=SEARCH&sid=UiB8IFFTIHwgUyB8IzIjICB8IG5vaWRhIzQjIHwgQ1AxIHwgWSB8IzE3IyAgfCAxICMyI3wgIHwgMzIzNzA4ODksMzEwMjUxMzEgfCAxIHwgNyM2IyB8IDEgfCM0MCMgIHw=&fsl=Y"
With Worksheets("Sheet1")
Range("B1") = driver.FindElementById("headerDescription").Text
dd = driver.FindElementById("pdPrice").Text
dd1 = driver.FindElementById("pricePerUnitArea").Text
Range("B2") = dd & dd1
dd3 = driver.findElementByClassName("pdPropAddress").Text
Range("B3") = dd3
End With
End Sub
答案 0 :(得分:0)
不要在保留字中键入大写
输入Three.WebGLUniforms
,VBA编辑器会将其更改为dd1 = driver.findelementbyid("pricePerUnitArea").text
(FindElementById中的大写字母)
输入dd1 = driver.FindElementById("pricePerUnitArea").Text
,vba编辑器会将其更改为dd3 = driver.findelementbyclassname("pdPropAddress").text
(无首都)
表示它无法识别dd3 = driver.findelementbyclassname("pdPropAddress").Text
你的专栏应该是findelementbyclassname
dd3 = driver.findelementbyclass("pdPropAddress").text
,否则With Worksheets("Sheet1")
行无用
.Range("B1") ...
与
相同With Worksheets("Sheet1")
.Range("B1") = driver.FindElementById("headerDescription").Text
End With
答案 1 :(得分:0)
试试这个。它会获取您所追求的结果。
Sub Use_Cell_text()
Dim driver As New FirefoxDriver, post As Object
driver.get "https://www.99acres.com/2-bhk-bedroom-apartment-flat-for-sale-in-jaypee-greens-kosmos-sector-134-noida-942-sq-ft-r1-spid-E31025131?pos=SEARCH&sid=UiB8IFFTIHwgUyB8IzIjICB8IG5vaWRhIzQjIHwgQ1AxIHwgWSB8IzE3IyAgfCAxICMyI3wgIHwgMzIzNzA4ODksMzEwMjUxMzEgfCAxIHwgNyM2IyB8IDEgfCM0MCMgIHw=&fsl=Y"
For Each post In driver.FindElementsByClass("pdPropAddress")
x = x + 1: Cells(x, 1) = post.Text
Next post
End Sub