2017-04-11 4 views
-1

私はredditソースコードからjスープを使用してユーザー名を取得しようとしていますが、それをDMにしようとしています。申し訳ありませんが、これは本当に面倒です。このようなJsoupを使用してRedditからユーザー名を引き出そうとしています

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

import java.io.IOException; 

public class Main 
{ 

public static void main(String[] args) { 

    Document doc; 
    try { 

     // need http protocol 
     doc = Jsoup.connect("https://www.reddit.com/new/).get(); 

     // get page title 
     String title = doc.title(); 
     System.out.println("title : " + title); 

     // get all links 
     Document doc = Jsoup.parse("https://www.reddit.com/new"); 
     Elements certainLinks = 
     doc.select("https://www.reddit.com/user"); { 

      // get the value from href attribute 
      { 
       System.out.println("\nlink : " + link.attr("href")); 
       System.out.println("text : " + link.text()); 

      } 


      catch (IOException e) { 
      e.printStackTrace(); 
     } 

     } 

    } 
    } 
+1

あなたの質問は何を持つすべてのaの要素を意味しますか? – tnw

+1

は私にスパムのように聞こえる – efekctive

答えて

1

なめらか

 Document doc = Jsoup.connect("https://www.reddit.com/new/").get(); 
     Elements certainLinks = doc.select("a[href*=https://www.reddit.com/user/]"); 
     certainLinks.forEach(l -> System.out.println(l.text())); 

が印刷されます:

_serial_chiller 
dracorian 
ImagesOfNetwork 
... 

a[href*=https://www.reddit.com/user/]を含むhref属性https://www.reddit.com/user/文字列

関連する問題