简体   繁体   English

使用Java从定位标记获取链接

[英]Get link from anchor tag using Java

I'm trying to get value of a href attribute from an anchor tag ( a tag) using Java, without a third party API. 我试图得到一个价值href从属性anchor标记( a使用Java标签),无需第三方API。 I know the class of the label. 我知道标签的类别。 The website looks like this: 该网站如下所示:

<html>
  <body>
    <div id="uix_wrapper">
      <div id="button">
          <label class="downloadButton">
            <a href="link that I want to get">Button</a>
          </label>
      </div>
    </div>
  </body>
</html>

You can use a regular expression if you try to avoid using any third-party libraries. 如果尝试避免使用任何第三方库,则可以使用正则表达式。 A very basic expression for your example is 您的示例的一个非常基本的表达式是

<a href="(.*?)">

and should work. 并且应该工作。 You can try out yourself using https://www.debuggex.com/ 您可以使用https://www.debuggex.com/尝试一下

The result will be in the second group. 结果将在第二组中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM