【问题标题】:based on a <tr> information click on a hyperlink in the same <tr><td> using Python基于 <tr> 信息单击同一 <tr><td> 中的超链接使用 Python
【发布时间】:2020-09-16 11:52:24
【问题描述】:

您好,我正在尝试单击位于 &lt;table&gt; 和特定 &lt;tr&gt;&lt;td&gt; 内的超链接,下面是 HTML 的样子

<tr><td>Clinic</td><td style="text-align:center">MN</td><td style="text-align:center">&nbsp;</td><td style="text-align:center"><input type="hidden" name="3572" value="1"><input type="checkbox" name="Alert_3572" value="1" checked="true"></td><td style="white-space:nowrap;text-align:center;"><a href="muniInfo.jsp?OBLI=3572&amp;current=FILING_HISTORY">Filing History</a></td><td style="text-align:center"></td></tr>

<tr><td>My Clinic</td><td style="text-align:center">MN</td><td style="text-align:center">&nbsp;</td><td style="text-align:center"><input type="hidden" name="3540" value="1"><input type="checkbox" name="Alert_3540" value="1" checked="true"></td><td style="white-space:nowrap;text-align:center;"><a href="muniInfo.jsp?OBLI=3540&amp;current=FILING_HISTORY">Filing History</a></td><td style="text-align:center"></td></tr>

我需要在这里做的是单击值 Clinic 的 &lt;a href&gt; 标记,但是根据 &lt;td&gt; = "Clinic 的值,不知道名称 (name="3572") 的值" 我需要用python点击相关的超链接

我能够使用美丽的汤检索所有 tr 和 td 标签,但不知道如何匹配值诊所,然后单击相邻的超链接。

我们将不胜感激。

【问题讨论】:

    标签: html python-3.x selenium-webdriver web-scraping beautifulsoup


    【解决方案1】:

    您可以使用 xpath 查询来检索元素。

    是这样的

    "//tr[td[text()='Clinic']]/td/a"
    

    这将为您带来tra 标记,其中包含td,其文本等于Clinic

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-14
      • 2018-10-26
      • 2019-06-18
      • 1970-01-01
      • 1970-01-01
      • 2021-09-14
      • 2014-12-06
      • 2018-06-30
      相关资源
      最近更新 更多