JPad
Snippets
Download
Help
Contact
fetch headlines using jsoup
Code
import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; String url = JPad.getArg(args, 0, "URL", "http://en.wikipedia.org/"); Document doc = Jsoup.connect(url).get(); Elements newsHeadlines = doc.select("h2"); Dump(Iterables.transform(newsHeadlines, e -> e.text()));
Result
Console
[From today's featured article, Did you know..., In the news, On this day..., From today's featured list, Today's featured picture, Other areas of Wikipedia, Wikipedia's sister projects, Wikipedia languages, Navigation menu]
Bytecode
Compiled from "RunnContainer.java" public class io.jpad.scratch.RunnContainer { public io.jpad.scratch.RunnContainer(); Code: 0: aload_0 1: invokespecial #1 // Method java/lang/Object."<init>":()V 4: return public static void main(java.lang.String...) throws java.lang.Exception; Code: 0: aload_0 1: iconst_0 2: ldc #2 // String URL 4: ldc #3 // String http://en.wikipedia.org/ 6: invokestatic #4 // Method io/jpad/scratch/JPad.getArg:([Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)Ljava/lang/String; 9: astore_1 10: aload_1 11: invokestatic #5 // Method org/jsoup/Jsoup.connect:(Ljava/lang/String;)Lorg/jsoup/Connection; 14: invokeinterface #6, 1 // InterfaceMethod org/jsoup/Connection.get:()Lorg/jsoup/nodes/Document; 19: astore_2 20: aload_2 21: ldc #7 // String h2 23: invokevirtual #8 // Method org/jsoup/nodes/Document.select:(Ljava/lang/String;)Lorg/jsoup/select/Elements; 26: astore_3 27: aload_3 28: invokedynamic #9, 0 // InvokeDynamic #0:apply:()Lcom/google/common/base/Function; 33: invokestatic #10 // Method com/google/common/collect/Iterables.transform:(Ljava/lang/Iterable;Lcom/google/common/base/Function;)Ljava/lang/Iterable; 36: invokestatic #11 // Method io/jpad/scratch/Dumper.Dump:(Ljava/lang/Object;)Ljava/lang/Object; 39: pop 40: return private static java.lang.String lambda$main$0(org.jsoup.nodes.Element); Code: 0: aload_0 1: invokevirtual #12 // Method org/jsoup/nodes/Element.text:()Ljava/lang/String; 4: areturn }
Jpad Version:1.07
viewCount:3352
Creator:
admin
Latest Editor:
admin
Tags
jsoup
Download
Copy As Markdown:
**code [fetch headlines using jsoup.java](/example/1E/fetch-headlines-using-jsoup)** import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.select.Elements; String url = JPad.getArg(args, 0, "URL", "http://en.wikipedia.org/"); Document doc = Jsoup.connect(url).get(); Elements newsHeadlines = doc.select("h2"); Dump(Iterables.transform(newsHeadlines, e -> e.text())); **Result:** [From today's featured article, Did you know..., In the news, On this day..., From today's featured list, Today's featured picture, Other areas of Wikipedia, Wikipedia's sister projects, Wikipedia languages, Navigation menu]