【问题标题】:How to extract the text 8 from the 2nd row and 2nd column as per the html through Selenium and VBA如何通过 Selenium 和 VBA 根据 html 从第 2 行和第 2 列中提取文本 8
【发布时间】:2018-09-17 09:09:22
【问题描述】:

使用 selenium v​​ba 我想要下面网页表格中的第二行和第二列值是我尝试过的代码,但它捕获了所有表格。

我想要的输出是 8。

driver.FindElementByXPath("//table[contains(@class,'zedoLocTable')]").text

请找到下面的 html 代码。

<tr>
<td colspan="4">
<div id="localityTiers">
<br><br>
<table class="zedoLocTable" cellpadding="0" cellspacing="0" width="100%">
<tbody>
<tr>
<th>TYPE</th>
<th>TIER</th></tr>
<tr>
<td><b>Resedential Sale</b>
</td><td>8</td>
</tr>
<tr><td><b>Resedential Rent</b>
</td><td>5</td>
</tr><tr>
<td><b>Commercial Sale</b>
</td><td>1</td>
</tr><tr>
<td><b>Commercial Lease</b>
</td><td>1</td>
</tr></tbody></table><table></table></div>
</td>
</tr>

下面是表格图片

【问题讨论】:

    标签: vba selenium xpath web-scraping webdriver


    【解决方案1】:

    根据您共享的 HTML 来提取文本 8,您可以使用以下解决方案:

    driver.FindElementByXPath("//table[@class='zedoLocTable']//tr/td/b[contains(.,'Resedential Sale')]//following::td[1]").text
    

    【讨论】:

    • 嗨,新贡献者和 Moshe Slavin 感谢您的回复,@新贡献者,您的代码运行良好!!!
    【解决方案2】:

    如果您正在使用更高版本的 IE 或除 IE 之外的其他浏览器,则可以使用比使用 xPath 更快的 CSS 选择器

    Debug.Print driver.FindElementByCSS(".zedoLocTable td + td").innerText
    

    【讨论】:

      猜你喜欢
      • 2018-04-29
      • 1970-01-01
      • 1970-01-01
      • 2020-01-01
      • 2016-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-20
      相关资源
      最近更新 更多