0

Piece of html code :

<a class="context_link" href="/thuc-don/41-Thit-vit-ram-sa-gung.html">
        <img src="http://monngonmoingay.com/uploads/monan/201205170430310000000_thit" +
                "-vit-ram-sa-gung-48aq570.png" alt="Thịt vịt ram sả gừng " />

so i use regex to get link from code :

String pat = "<a\\s+class=\"context_link\"\\s+href=\"(.+)\"";       
   Pattern pattern = Pattern.compile(pat,Pattern.DOTALL | Pattern.UNIX_LINES);
   Matcher math = pattern.matcher(source);
   while(math.find()){Log.i("Value",math.group(1));}

When i check is match or not, result always is false.

Who can help me fix error it ?

Chris H
  • 271
  • 1
  • 6
  • 19

1 Answers1

0

If you're trying to extract HREF then you should use Jsoup library

Jsoup

Now working example:

import java.io.IOException;

import org.jsoup.Jsoup;

public class Test {

    public static void main(String args[]) throws IOException {

        String source = "<a class=\"context_link\" href=\"/thuc-don/41-Thit-vit-ram-sa-gung.html\">        <img src=\"http://monngonmoingay.com/uploads/monan/201205170430310000000_thit\" +                \"-vit-ram-sa-gung-48aq570.png\" alt=\"Th?t v?t ram s? g?ng \" />";
        String link = Jsoup.parse(source).select("a").first().attr("href");
        System.out.println("Your link  :" + link);

    }

}
Makky
  • 17,117
  • 17
  • 63
  • 86