Skip to content

Instantly share code, notes, and snippets.

@Nekodigi
Created September 11, 2020 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nekodigi/efd0e47bc07d15b194798eca61e426f2 to your computer and use it in GitHub Desktop.
Save Nekodigi/efd0e47bc07d15b194798eca61e426f2 to your computer and use it in GitHub Desktop.
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