Created
September 11, 2020 14:34
-
-
Save Nekodigi/efd0e47bc07d15b194798eca61e426f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
import java.io.IOException; | |
import org.jsoup.Jsoup; | |
import org.jsoup.nodes.Document; | |
import org.jsoup.nodes.Element; | |
import org.jsoup.select.Elements; | |
public class Main { | |
public static void main(String[] args) { | |
// write your code here | |
//try-catch文が必要 | |
try { | |
//Document A = Jsoup.connect("url").get(); urlにスクレイピング対象 | |
Document doc = Jsoup.connect("https://plancke.io/hypixel/player/stats/Nekodigi#Arcade").get(); | |
//Elements B = A.select("タグ"); この形でソースに含まれるタグで指定された範囲を書き出す。 | |
Elements tables = doc.select("table"); | |
Element table = tables.get(0); | |
Elements rows = table.select("tr"); | |
//拡張for文 | |
for(Element row : rows) { | |
Elements tds = row.select("td"); | |
for(Element td : tds) { | |
String tdt = td.text(); | |
System.out.print(tdt+" "); | |
} | |
System.out.println(); | |
} | |
//例外処理 | |
}catch(IOException e) { | |
e.printStackTrace(); | |
System.out.println("error"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment