2
私は、Webページからデータを抽出するためにHTMLを解析する必要があるプロジェクトに取り組んでいます。私はJavaでJsoupを使用しています。私は以下の内容からデータを抽出する必要があります。HTML href属性の解析
<tr>
<td><small><a href="http://www.timeanddate.com/worldclock/fixedtime.html?iso=20160821T2100&p1=248" target="_blank">2016/08/21 21:00</a></small></td>
<td><small><a href="https://agc003.contest.atcoder.jp">AtCoder Grand Contest 003</a></small></td>
</tr>
「コンテスト名」と「時間」の値は取得できますが、URLの抽出方法はわかります。私はコンテストのURLを取得したいhttps://agc003.contest.atcoder.jp
これを得る方法??
EDIT: ここに私のコード
private void getAC() throws IOException {
Document doc = Jsoup.connect("https://atcoder.jp/").userAgent(Desktop.getDesktop().toString()).get();
Element table = doc.getElementsByClass("table-responsive").get(1);
Elements contestStartTime = table.getElementsByTag("td");
int cnt = 1;
for (Element i : contestStartTime) {
System.out.println(cnt + ". " + i.html());
cnt++;
}
}
私はf JSoupやJavaに慣れていますが、ファイルを読み込んで行単位で読み込み、正規表現パターンを使用してを検索し、その行からURLを解析します。 – dinotom
コンテストの名前と時間を取得するためのコードを追加できますか? – TDG
タグにはidやanyhingが付いていないようですので、わかりません。しかし、一度あなたが要素を見つけるとURLを取得するのは簡単です。 'Elements.attr(" href ")'は、i.attr( "href")を使用して値 –