【问题标题】:Vba code to get data rank of a specific project from listingVba代码从列表中获取特定项目的数据排名
【发布时间】:2018-03-05 16:53:20
【问题描述】:

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

图片-

我的 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

【问题讨论】:

    标签: vba selenium firefox


    【解决方案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")
    

    【讨论】:

    • 嗨 DebanjanB,这正是我要找的。工作一种享受。谢谢!
    猜你喜欢
    • 2018-11-14
    • 1970-01-01
    • 2011-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-22
    • 2017-02-16
    • 1970-01-01
    相关资源
    最近更新 更多