【问题标题】:VBA code to scrape the price of particular project from URL [duplicate]从 URL 中获取特定项目价格的 VBA 代码 [重复]
【发布时间】:2018-11-14 15:15:00
【问题描述】:

我正在尝试从 URL 获取特定项目的价格详细信息,但我一无所知。

示例:-来自 Eden Richmond Enclave 项目的 url (https://www.99acres.com/ppc-2515-residential-apartment-mailer) 我想要价格 14.22 to 31.15 Lac in range A1

下面是我试过的代码:

Sub test()
Set driver = CreateObject("Selenium.FirefoxDriver")
driver.get "https://www.99acres.com/ppc-2515-residential-apartment-mailer"
Range("A1") = driver.FindElementByXPath("//h1[contains(@class,'font-size15')][contains(text(),'Eden Richmond Enclave')][contains(@class,'product-lrg-box')]").Text
End Sub

图片

下面是html代码:-

<div class="pro-text">
                  <div class="product-text-box">
                    <div class="product-heading"><span><img src="https://newprojects.99acres.com/projects/eden_group/eden_richmond_enclave/bb7ttfq9.gif">
                      <h1 class="font-size15">Eden Richmond Enclave                        <p>Narendrapur</p>
                      </h1>
                      </span> </div>
                  </div>
                  <div class="product-text-box">
                    <ul class="product-lrg-box">
			                       <li> <span><strong><span class="rupee-font">₹ &nbsp;</span>14.22 to 31.15 Lac</strong></span></li>
						                      <li><strong>499-1093 SQFT</strong></li>
							
                      <li><strong>1-3 BHK</strong></li>
						                      <li style="width:20% !important;"><strong>December 2020</strong></li>
			                    </ul>
                    <div id="tabs" class="tab-link tabs-menu tabs-menu-new">
                      <ul>
                        <li><a href="#294015broch">e-Brochure</a></li>
			                        <li><a href="#294015amn">Amenities</a></li>
						                      <!--  <li style="width:20% !important;"><a href="#294015floor">Floor Plan</a></li>-->
						                        <li style="width:20% !important;"><a href="#294015dir">Directions</a></li>
			                      </ul>
                    </div>
                    <span class="enquire-new-bt" id="294015-469203,151100-enquire-new-bt" data-val="2"> <a href="javascript:void(0)">I am Interested</a> </span> </div>
			                </div>

【问题讨论】:

  • 您使用的是 Selenium 和 vba?这需要使用firefox来完成吗?
  • 嗨 ashleedawg 感谢您的回复,是的,我正在使用 selenium v​​ba 和 firefox。
  • 能否显示相关的HTML。
  • 以上发生了什么?
  • 除非有理由需要使用这些平台,否则我建议您只使用vba 并使用internet-explorer 进行如此简单的抓取工作,如果您有兴趣,这里有一个excellent tutorial。 IE 是非常标准的用于 VBA 的浏览器。 (作为一个 Firefox 用户,VBA 是我安装 IE 的唯一原因。我研究过使用 Firefox,它是可能的,但没有很多可用的文档/示例。 )

标签: vba selenium firefox web-scraping


【解决方案1】:

不妨试试

.FindElementByCSS("ul.product-lrg-box span")

取决于您是否打算对其他元素重复此过程。

对于上述内容,使用您提供的 HTML,您将获得:

否则,

.FindElementByCSS("ul.product-lrg-box")

检索整个字符串。

无法查看页面并知道是否要检索更多可能考虑的元素

.FindElementsByCss("ul.product-lrg-box span") 

并遍历返回的集合(如果有效);或者,

尝试用 IE 抓取并使用类似的东西:

 IE.documentQuerySelectorAll("ul.product-lrg-box span")

然后遍历返回的 NodeList。

【讨论】:

  • 嗨 QHarr 感谢您的回复,我在这个 url 中有大约 5 个项目,当我运行 .FindElementByCss("ul.product-lrg-box span") 时,我只想要 Eden Richmond Enclave 项目价格。文本然后它只提取第一个项目细节,但 Eden Richmond Enclave 项目位于第二个位置。
  • FindElementsByCss("ul.product-lrg-box span")(1).Text ?
  • 我猜是因为你有另一个答案,你懒得回应这个?
【解决方案2】:

要提取文本 14.22 到 31.15 Lac,您可以使用以下任一Locator Strategies

  • XPath

    //h1[contains(.,'Eden Richmond Enclave')]//following::div[1]/ul[@class='product-lrg-box']/li//span/strong[not(@class='rupee-font')]
    

【讨论】:

  • 嗨 DebanjanB 感谢您的回复,它对我有用!!!
猜你喜欢
  • 1970-01-01
  • 2015-11-21
  • 1970-01-01
  • 2011-02-11
  • 2021-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多