Sunday, 15 March 2015

java - Android Regular expression grab an image url from a site -



java - Android Regular expression grab an image url from a site -

i making app , have problem utilize patter recognition code find image url of article @ site.

the problem in way grabs first photo small.

pattern p = pattern.compile("http://planetaris.gr/media/k2/items/cache.*\.jpg"); there xl image grab destination.

i utilize pattern @ end of link goes this

pattern p = pattern.compile("(http://planetaris.gr/media/k2/items/cache.)+(.*\[_xl]+(.jpg))");

or pattern p = pattern.compile("http://planetaris.gr/media/k2/items/cache.*\_xl.jpg");

this need help here code

public void run() {

//pattern p = pattern.compile("http://planetaris.gr/media/k2/items/cache.*\\.jpg"); //pattern p = pattern.compile("http://planetaris.gr/media/k2/items/cache.*\\._xl.jpg"); pattern p = pattern.compile("(http://planetaris.gr/media/k2/items/cache.)+(.*\\[_xl]+(.jpg))"); seek { url url = new url(selectedrssitem.getlink()); urlconnection urlc = url.openconnection(); log.d("mimis_link", url.tostring()); bufferedinputstream buffer = new bufferedinputstream(urlc.getinputstream()); builder = new stringbuilder(); int byteread; while ((byteread = buffer.read()) != -1) builder.append((char) byteread); buffer.close(); } grab (malformedurlexception ex) { ex.printstacktrace(); } grab (ioexception ex) { ex.printstacktrace(); } matcher m = p.matcher(builder.tostring()); if (m.find()) { seek { bitmap = bitmapfactory.decodestream((inputstream)new url(m.group(0)).getcontent()); } grab (malformedurlexception e) { // todo auto-generated grab block e.printstacktrace(); } grab (ioexception e) { // todo auto-generated grab block e.printstacktrace(); } log.d("mimis_matcher", selectedrssitem.getdescription().tostring()); }; handler.sendemptymessage(0); } }.start(); } private handler handler = new handler() { //@suppresswarnings("null") @override public void handlemessage(message msg) { mspinner.clearanimation(); mspinner.setvisibility(view.gone); //progressdialog.dismiss(); myimageview.setimagebitmap(bitmap); if (bitmap==null){ myimageview.setimageresource(r.drawable.aris_no_image); }; } };

because @ site there jpg has xl

these .jpg @ given page .

href="/media/k2/items/cache/df95c3d9029788dcdb6f520e9151056c_xl.jpg"

/media/k2/items/cache/df95c3d9029788dcdb6f520e9151056c_l.jpg"

"/images/stories/atnea2.jpg"

/images/stories/diarkeias-bc.jpg"

this regex: /(media|images)/[^\.]*\.jpg

matches samples:

href="/media/k2/items/cache/df95c3d9029788dcdb6f520e9151056c_xl.jpg" /media/k2/items/cache/df95c3d9029788dcdb6f520e9151056c_l.jpg" "/images/stories/atnea2.jpg" /images/stories/diarkeias-bc.jpg"

java android regex pattern-matching expression

No comments:

Post a Comment