java - Parsing jsoup url android -



java - Parsing jsoup url android -

i can parse href url next documentation:

document doc = jsoup.connect("http://jsoup.org").get(); element link = doc.select("a").first(); string relhref = link.attr("href"); // == "/" string abshref = link.attr("abs:href"); // "http://jsoup.org/"

but seek extract link url css in webpage: http://multiplayer.it/notizie/133685-assassins-creed-unity-ecco-come-assassins-creed-unity-sfrutta-lhardware-di-nuova-generazione.html

i need take link of image banner. id is: id="content_heading" image loaded css.

<div id="content_heading" style="background: url(http://images.multiplayer.it/thumbs/images/2014/06/10/assassins_creed_unity_jpg_1600x0_upscale_q85.jpg) center center; background-size: cover;">

how can extract url? asynktask

private class contentviewimgurl extends asynctask<string,string,string> { @override protected void onpreexecute() { } @override protected string doinbackground(string... params) { seek { final document doc = jsoup.connect(url).timeout(30000).get(); runonuithread(new runnable() { @override public void run() { element rootelement = doc.body().getelementbyid("top_ads_container"); elements elements = rootelement.getelementsbytag("header"); for(element element : elements){ imgurlpost = element.select("div.content_heading").text(); } } }); } grab (exception e) { log.e("esempio", "error"); } homecoming null; // modified here } @override protected void onpostexecute(string result) { toast.maketext(singleactivity.this, "url "+ imgurlpost, toast.length_short).show(); } }

the toast not works.. returns url , nil else. thanks

udpate:

private class contentviewimgurl extends asynctask<void,void,void> { final pattern pattern = pattern.compile("url\\((.+?)\\)"); @override protected void onpreexecute() {} @override protected string doinbackground(void... params) { seek { final document doc = jsoup.connect(url).timeout(30000).get(); runonuithread(new runnable() { @override public void run() { string url = doc.getelementbyid("content_heading").attr("style").tostring(); matcher matcher = pattern.matcher(url); matcher.find(); system.out.println(matcher.group(1)); } }); urlnew = new url(matcher.group(1)); postbitmap = bitmapfactory.decodestream(urlnew.openconnection().getinputstream()); } grab (exception e) { log.e("esempio", "error"); } homecoming null; // modified here } @override protected void onpostexecute(void result) { toast.maketext(singleactivity.this, "url "+ urlnew, toast.length_short).show(); postimage = (imageview) findviewbyid(r.id.postimage); postimage.setimagebitmap(postbitmap); } }

where urlnew declared public url urlnew , postbitmap bitmap

second udpate:

private class contentviewimgurl extends asynctask<void,void,void> { final pattern pattern = pattern.compile("url\\((.+?)\\)"); @override protected void onpreexecute() {} @override protected string doinbackground(void... params) { seek { final document doc = jsoup.connect(url).timeout(30000).get(); runonuithread(new runnable() { @override public void run() { string url = doc.getelementbyid("content_heading").attr("style").tostring(); matcher matcher = pattern.matcher(url); if(matcher.find()){ system.out.println(matcher.group(1)); indirizzostringaimg = matcher.group(1); imgloader = imageloader.getinstance(); imgloader.init(imageloaderconfiguration.createdefault(getactivity())); system.out.println(urlnew); } else { toast.maketext(getactivity(), "pic url error", toast.length_short).show(); } } }); } grab (exception e) { log.e("esempio", "error"); } homecoming null; // modified here } @override protected void onpostexecute(void result) { if(matcher.find()){ displayimageoptions opt = new displayimageoptions.builder() .showstubimage(r.drawable.refresh) .showimageforemptyuri(r.drawable.refresh) .cacheinmemory() .imagescaletype(imagescaletype.in_sample_int) .cacheondisc() .build(); imgloader.displayimage(indirizzostringaimg, postimage_main, opt); } else { toast.maketext(getactivity(), "pic url error", toast.length_short).show(); } } }

here finish working example. part interests you.

import java.util.regex.matcher; import java.util.regex.pattern; import org.jsoup.jsoup; import org.jsoup.nodes.document; public class main { public static void main(string[] args) { string html = "<div id=\"content_heading\" style=\"background: url(http://images.multiplayer.it/thumbs/images/2014/06/10/assassins_creed_unity_jpg_1600x0_upscale_q85.jpg) center center; background-size: cover;\"></div>"; final pattern pattern = pattern.compile("url\\((.+?)\\)"); seek { document doc = jsoup.parse(html); string url = doc.getelementbyid("content_heading").attr("style").tostring(); matcher matcher = pattern.matcher(url); matcher.find(); system.out.println(matcher.group(1)); } catch(exception e) { e.printstacktrace(); } } }

update

private class contentviewimgurl extends asynctask<string,string,string> { final pattern pattern = pattern.compile("url\\((.+?)\\)"); @override protected void onpreexecute() {} @override protected string doinbackground(string... params) { seek { final document doc = jsoup.connect(url).timeout(30000).get(); runonuithread(new runnable() { @override public void run() { string url = doc.getelementbyid("content_heading").attr("style").tostring(); matcher matcher = pattern.matcher(url); matcher.find(); system.out.println(matcher.group(1)); } }); } grab (exception e) { log.e("esempio", "error"); } homecoming null; // modified here } @override protected void onpostexecute(string result) { toast.maketext(singleactivity.this, "url "+ imgurlpost, toast.length_short).show(); } }

java android html css jsoup

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -