Skip to content

Instantly share code, notes, and snippets.

@mdk-aza
Last active April 24, 2016 15: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 mdk-aza/89ae9940e5371fc7e095c34828c4c400 to your computer and use it in GitHub Desktop.
Save mdk-aza/89ae9940e5371fc7e095c34828c4c400 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/PuerkitoBio/goquery"
"fmt"
"strings"
)
type Tournaments struct {
Tournament []Tournament
}
type Tournament struct {
Title string
Level string //後々フィルタリングに使いたい
eventOutlines []EventOutline
}
type EventOutline struct {
TheDate string
CourtSurface string
MeetingTime string
MeetingPlace string
EntryFee string
PTR string
WantedSituation string
}
func main() {
url := "http://minamiichikawa.jp/pg214.html"
GetPage(url)
}
func GetPage(url string) {
doc, err := goquery.NewDocument(url)
if err != nil {
fmt.Print("url scarapping failed")
}
tournaments := Tournaments{Tournament:make([]Tournament, 0)}
doc.Find(".box").Each(func(tournamentLevel int, tournamentPage *goquery.Selection) {
tournament := Tournament{Title:tournamentPage.Find(".h3").Text(), eventOutlines:make([]EventOutline, 0)}
tournaments.Tournament = append(tournaments.Tournament, tournament)
//レベル別のループ
tournamentPage.Find("table > tbody").Each(func(_ int, events *goquery.Selection) {
eventOutlines := make([]EventOutline, 0)
//大会ごとのループ
events.Find("tr").Each(func(_ int, event *goquery.Selection) {
eventInfos := strings.Split(strings.TrimSpace(event.Text()), "\n")
eventOutline := EventOutline{
TheDate:eventInfos[0],
CourtSurface:eventInfos[1],
MeetingTime:eventInfos[2],
MeetingPlace:eventInfos[3],
EntryFee:eventInfos[4],
PTR:eventInfos[5],
WantedSituation:eventInfos[6]}
eventOutlines = append(eventOutlines, eventOutline)
})
tournaments.Tournament[tournamentLevel].eventOutlines = eventOutlines
})
})
fmt.Println(tournaments.Tournament)
//出力結果
//[{マスターズ男子シングルス(出場制限あり) [{日程 開催 集合時間 集合場所 参加費 PTR 募集状況} {12月6日(日) インドア 17:30 アウト側 ¥4,100 - 募集中}]}
// {男子シングルス(オープン大会) [{日程 開催 集合時間 集合場所 参加費 PTR 募集状況} {5月7日(土) インドア 17:30 アウト側 ¥4,100 - キャンセル待ち} {6月12日(日) インドア 16:30 アウト側 ¥4,100 - 募集中}]}
// {セミオープン男子シングルス(出場制限あり) [{日程 開催 集合時間 集合場所 参加費 PTR 募集状況} {4月24日(日) インドア 17:30 アウト側 ¥4,100 - キャンセル待ち} {5月3日(火祝) アウトドア 16:30 アウト側 ¥3,600 - 募集中} {5月22日(日) インドア 17:30 アウト側 ¥4,100 - 募集中} {6月18日(土) アウトドア 16:30 アウト側 ¥3,600 - 募集中}]}
// {アドバンス男子シングルス(出場制限あり) [{日程 開催 集合時間 集合場所 参加費 PTR 募集状況} {4月17日(日) アウトドア 16:30 アウト側  ¥4,100 - キャンセル待ち} {4月29日(金祝) インドア 17:30 アウト側  ¥4,100 - キャンセル待ち} {5月4日(水祝) アウトドア 16:30 アウト側  ¥4,100 - キャンセル待ち} {5月8日(日) アウトドア 16:30 アウト側  ¥3,600 - 募集中} {5月28日(土) アウトドア 16:30 アウト側  ¥3,600 - 募集中} {6月5日(日) アウトドア 16:30 アウト側  ¥4,100 - 募集中}]}
// {ビギナー男子シングルス(出場制限あり) [{日程 開催 集合時間 集合場所 参加費 PTR 募集状況} {5月3日(火祝) アウトドア 10:30 アウト側 ¥4,100 - キャンセル待ち} {5月5日(木祝) インドア 17:30 アウト側 ¥4,600 - キャンセル待ち} {5月14日(土) アウトドア 16:30 アウト側 ¥4,100 - キャンセル待ち} {5月29日(日) アウトドア 16:30 アウト側 ¥4,100 - キャンセル待ち} {6月4日(土) アウトドア 16:30 アウト側 ¥4,100 - 募集中} {6月19日(日) アウトドア 17:30 アウト側 ¥4,100 - 募集中}]}
// {年齢別男子シングルス(年齢制限あり) [{日程 開催 集合時間 集合場所 参加費 PTR 募集状況} {4月10日(日) インドア 17:30 アウト側 ¥4,600 - キャンセル待ち} {5月1日(日) アウトドア 16:30 アウト側 ¥4,100 - 募集中}]}
// {マスターズ女子シングルス(出場制限あり) [{日程 開催 集合時間 集合場所 参加費 PTR 募集状況} {1月17日(日) インドア 15:30 イン側 ¥4,600 - キャンセル待ち}]}
// {女子シングルス(オープン大会) [{日程 開催 集合時間 集合場所 参加費 PTR 募集状況} {5月21日(土) インドア 17:30 アウト側 ¥4,600 - 募集中} {6月12日(日) インドア 17:00 イン側 ¥4,600 - 募集中}]}
// {セミオープン女子シングルス(出場制限あり) [{日程 開催 集合時間 集合場所 参加費 PTR 募集状況} {2月12日(金) インドア 10:30 イン側 ¥4,100 - 中止} {4月10日(日) インドア 17:00 イン側 ¥4,600 - 募集中}]}
// {アドバンス女子シングルス(出場制限あり) [{日程 開催 集合時間 集合場所 参加費 PTR 募集状況} {3月26日(土) アウトドア 16:30 アウト側 ¥4,100 - 募集中} {4月17日(日) インドア 17:00 イン側 ¥4,600 - 募集中} {5月2日(月) インドア 10:30 イン側 ¥4,100 - 募集中} {5月15日(日) アウトドア 16:30 アウト側 ¥4,100 - 募集中}]}
// {フレッシュ女子シングルス出場制限あり [{日程 開催 集合時間 集合場所 参加費 PTR 募集状況} {4月15日(金) インドア 10:30 イン側 ¥4,100 - 中止} {4月30日(土) インドア 17:30 アウト側 ¥4,600 - 募集中} {5月5日(木祝) アウトドア 10:30 アウト側 ¥4,100 - 募集中} {6月11日(土) アウトドア 16:30 アウト側 ¥4,100 - 募集中} {6月17日(金) インドア 10:30 イン側 ¥4,100 - 募集中}]}]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment