【问题标题】:How do I get the text "Job id" from this:我如何从中获取文本“Job id”:
【发布时间】:2016-05-25 09:43:06
【问题描述】:
<a name="HRS_AGNT_RSLT_I$srt7$0" 
id="HRS_AGNT_RSLT_I$srt7$0" 
tabindex="109" 
class="PSLEVEL1GRIDCOLUMNHDR" href="javascript:submitAction_win0(document.win0,'HRS_AGNT_RSLT_I$srt7$0');" title="Click column heading to sort descending">Job ID</a>.`

我想从上面的代码中获取“job id”文本。 我已经尽我所能,但仍然无法找到出路。 这真的让我在这个项目上停留了一段时间。 我需要有人帮助我。

【问题讨论】:

    标签: css ruby screen-scraping


    【解决方案1】:

    只需使用:document.getElementById("myAnchor").text

    例如,复制并粘贴此内容并告诉我它是否有帮助:

    <!DOCTYPE html>
    <html>
    <body>
    
    <p><a id="myAnchor" href="http://www.example.com/test.htm#part2">Example link</a></p>
    
    <p>Click the button to display the text content of the link above.</p>
    
    <button onclick="myFunction()">Try it</button>
    
    <p id="demo"></p>
    
    <script>
    function myFunction() {
        var x = document.getElementById("myAnchor").text;
        document.getElementById("demo").innerHTML = x;
    }
    </script>
    
    </body>
    </html>
    

    【讨论】:

      【解决方案2】:

      尝试使用正则表达式。

      s = "<a name=\"HRS_AGNT_RSLT_I$srt7$0\" id=\"HRS_AGNT_RSLT_I$srt7$0\" tabindex=\"109\" class=\"PSLEVEL1GRIDCOLUMNHDR\" href=\"javascript:submitAction_win0(document.win0,'HRS_AGNT_RSLT_I$srt7$0');\" title=\"Click column heading to sort descending\">Job ID</a>."
      reg = /<a.+>(.+)<\/a>/
      s[reg, 1]
      # => "Job ID"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-05-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多