Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何获取href标记之外的链接? 私有静态最终模式ptninhref=Pattern.compile( “(?:.\\\]*(?i)href(?-i)=\\\\”[^\\\“]*)([^\\\”]*)”; 公共静态列表captureValuesinhref(字符串largeText){ Matcher mtchinhref=ptninhref.Matcher(largeText); List inHREF=new ArrayList(); while(mtchinhref.find()){ inHREF.add(mtchinhref.group());_Java_Html_Netbeans_Web Scraping - Fatal编程技术网

Java 如何获取href标记之外的链接? 私有静态最终模式ptninhref=Pattern.compile( “(?:.\\\]*(?i)href(?-i)=\\\\”[^\\\“]*)([^\\\”]*)”; 公共静态列表captureValuesinhref(字符串largeText){ Matcher mtchinhref=ptninhref.Matcher(largeText); List inHREF=new ArrayList(); while(mtchinhref.find()){ inHREF.add(mtchinhref.group());

Java 如何获取href标记之外的链接? 私有静态最终模式ptninhref=Pattern.compile( “(?:.\\\]*(?i)href(?-i)=\\\\”[^\\\“]*)([^\\\”]*)”; 公共静态列表captureValuesinhref(字符串largeText){ Matcher mtchinhref=ptninhref.Matcher(largeText); List inHREF=new ArrayList(); while(mtchinhref.find()){ inHREF.add(mtchinhref.group());,java,html,netbeans,web-scraping,Java,Html,Netbeans,Web Scraping,如何仅获取“已提供链接”? 当我使用(?:.*]*(?i)href(?-i)=\“[^\”]*)([^\“]*)(?:[^\“]*.*.*)这个正则表达式代码时,它会给我如下输出: 但仅要求输出:“此处提供链接” 我需要href标签之外的链接。 有两个链接: 1位于href标记内。 2位于浏览器中显示的href标记之外。 我只需要第二个链接。 如何在netbeans中使用java获取它?公共类regexample{ private static final Pattern ptninhref =

如何仅获取
“已提供链接”

当我使用
(?:.*]*(?i)href(?-i)=\“[^\”]*)([^\“]*)(?:[^\“]*.*.*)
这个正则表达式代码时,它会给我如下输出:


但仅要求输出:
“此处提供链接”

我需要href标签之外的链接。

有两个链接:
1位于href标记内。
2位于浏览器中显示的href标记之外。
我只需要第二个链接。
如何在netbeans中使用java获取它?

公共类regexample{
private static final Pattern ptninhref =Pattern.compile(
            "(?:.*\\<[aA][^\\>]*(?i)href(?-i)=\\\"[^\\\"]*)([^\\\"]*)");

    public static List<String> captureValuesinhref(String largeText){
        Matcher mtchinhref = ptninhref.matcher(largeText);
        List<String> inHREF = new ArrayList<>();
        while(mtchinhref.find()){
           inHREF.add(mtchinhref.group());
/** *@param args */ 公共静态void main(字符串[]args){ 字符串href=“”;
String regexOr=“(?])(\ \ \ \?)*?(?=[我不完全理解这个问题,您介意详细说明吗?也许可以添加一些您迄今为止尝试的代码。您是否解开了我想问的问题?不,我不明白您的问题。我想获取一个在href标记W3Schools.com之外的URL!它只提供run:BUILD SUCCESSFUL(总时间:0秒)只有当标签{}外有一些文本(字符串)时,它才起作用。这里的意思是“Visit W3Schools.com!”是一个字符串。因此它会给出输出,但当有像{}这样的链接(URL)时,它就不起作用了。你试过“public class regexample{…}”吗?它应该打印:“Visit W3Schools.com!”!“,如您所愿。请举例说明字符串largeText的外观如何?我已尝试..String href=”“;将此字符串作为输入字符串href=“paypal.com/signin/”>https://www.paypa1.com/signin/ 因此,如何仅获取标记内的URL(带“)
public class RegexExample {

    /**
     * @param args
     */
    public static void main(String[] args) {

        String href= "<a href=\"w3schools.com\">Visit W3Schools.com!</a>";
        String regexOr = "(?<=[>])(\\\\?.)*?(?=[<])";
        Pattern pattern = Pattern.compile(regexOr);
        Matcher matcher = pattern.matcher(href);
        if (matcher.find()) {
            String enrichedValue = matcher.group();
            System.out.print(enrichedValue);
        }
    }
}
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexExample {
    private static final Pattern ptninhref;
    static{
        ptninhref = Pattern.compile("(?<=[>])(\\\\?.)*?(?=[<])");
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        String href= "<a href=\"paypal.com/signin/\">https://www.paypa1.com/signin/</a>";
        List<String> results = captureValuesinhref(href);
        for(String result:results){
            System.out.print(result);
        }
    }

    public static List<String> captureValuesinhref(String largeText){
        Matcher mtchinhref = ptninhref.matcher(largeText);
        List<String> inHREF = new ArrayList<String>();
        while(mtchinhref.find()){
           inHREF.add(mtchinhref.group());
        }
        return inHREF;
    }
}