Vba代码从列表中获取特定项目的数据排名

时间:2018-03-05 07:51:41

标签: vba selenium firefox

我正试图从列表中获取特定项目的数据排名。 示例-Morpheus Greens项目位于列表中的数据排名第11位。如下图所示。我想要在范围A1中的数据排名计数11。 下面是我试过但没有运气的vba代码。

的图像 -

enter image description here

我的vba代码 -

Sub Class_Initialize()
Set driver = CreateObject("Selenium.FirefoxDriver")
driver.get "https://www.99acres.com/search/project/buy/residential/sector-78-noida?search_type=QS&search_location=CP1&lstAcn=CP_R&lstAcnId=1&src=CLUSTER&preference=S&selected_tab=3&city=7&res_com=R&isvoicesearch=N&keyword_suggest=sector-78%20noida%3B&np_search_type=R2M%2CNL%2CNP&fullSelectedSuggestions=sector-78%20noida&strEntityMap=W3sidHlwZSI6ImxvY2FsaXR5In0seyIxIjpbInNlY3Rvci03OCBub2lkYSIsIkNJVFlfNywgTE9DQUxJVFlfODM5OCwgUFJFRkVSRU5DRV9TLCBSRVNDT01fUiJdfV0%3D&texttypedtillsuggestion=sector&refine_results=Y&Refine_Localities=Refine%20Localities&action=%2Fdo%2Fquicksearch%2Fsearch&suggestion=CITY_7%2C%20LOCALITY_8398%2C%20PREFERENCE_S%2C%20RESCOM_R&searchform=1&locality=8398&price_min=null&price_max=null"
driver.Window.Maximize
driver.Wait 2000
driver.FindElementByXPath("//a[contains(@class,'npt_titl_desc')][contains(text(),'Morpheus Greens')]").ScrollIntoView
driver.FindElementByXPath("//a[contains(@class,'npt_titl_desc')][contains(text(),'Morpheus Greens')]").Size = Range("A1")
'My output should 11
End Sub

1 个答案:

答案 0 :(得分:1)

要提取data-rank点数 11 ,您可以使用以下代码行:

driver.FindElementByXPath("//a[@class='npt_titl_desc' and contains(.,'Morpheus Greens')]//ancestor::div[@class='npsrp_card srpWrap' and @data-projid='R35476']").Attribute("data-rank")