2011-05-31 80 views
0

我有一個問題,從jsoup下面的性質的HTML提取鏈接。提取鏈接的背景,jsoup

<div class="post_video" style="background-image:url(http://img.youtube.com/vi/JFf3uazyXco/2.jpg);"> 

回答

4

這就是我該怎麼做的。

import org.jsoup.Jsoup; 
import org.jsoup.nodes.Document; 
import org.jsoup.nodes.Element; 
import org.jsoup.select.Elements; 


public class JSoup { 
    public static void main(String[] args) { 
     String html = "<html><head></head><body><div class=\"post_video\" style=\"background-image:url(http://img.youtube.com/vi/JFf3uazyXco/2.jpg);\"></body></html>"; 

     Document doc = Jsoup.parse(html); 
     Elements elements = doc.getElementsByClass("post_video"); 

     for(Element e : elements) { 
      String attr = e.attr("style"); 
      System.out.println(attr.substring(attr.indexOf("http://"), attr.indexOf(")"))); 
     } 
    } 

} 
+0

謝謝,它的工作原理。 – jumper0k 2011-05-31 23:49:23