Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scraping logic after site changes #8

Merged
merged 1 commit into from
Apr 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions rubbish.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ type refuseParser struct {

// Parse parses the auckland council rubbish webpage.
func (p *refuseParser) parse(r io.Reader) ([]RubbishCollection, error) {
const datesSection = "#ctl00_SPWebPartManager1_g_dfe289d2_6a8a_414d_a384_fc25a0db9a6d_ctl00_pnlHouseholdBlock"
p.detail = make([]RubbishCollection, 2)
const datesSection = "#ctl00_SPWebPartManager1_g_dfe289d2_6a8a_414d_a384_fc25a0db9a6d_ctl00_pnlHouseholdBlock2"
p.detail = make([]RubbishCollection, 3)
doc, err := goquery.NewDocumentFromReader(r)
if err != nil {
return nil, err
}
_ = doc.Find(datesSection).
Children().
Slice(1, 3).
Slice(1, 4).
Each(p.parseLinks) // p.parseLinks populates p.detail
for i := range p.detail {
if err := (&p.detail[i]).parseDate(); err != nil {
Expand All @@ -152,15 +152,9 @@ func (p *refuseParser) parse(r io.Reader) ([]RubbishCollection, error) {

// parseLinks parses the links within selection
func (p *refuseParser) parseLinks(el int, sel *goquery.Selection) {
sel.Children().Each(func(n int, sel *goquery.Selection) {
sel.Children().Children().Each(func(n int, sel *goquery.Selection) {
switch n {
case 0:
if dow.FindString(sel.Text()) == "" {
log.Println("unable to detect day of week")
return
}
p.detail[el].Day = sel.Text()
default:
if sel.Text() == "Rubbish" {
p.detail[el].Rubbish = true
} else if sel.Text() == "Food scraps" {
Expand All @@ -170,6 +164,12 @@ func (p *refuseParser) parseLinks(el int, sel *goquery.Selection) {
} else {
p.Err = fmt.Errorf("parse error: sel.Text = %q, el = %d, n = %d", sel.Text(), el, n)
}
default:
if dow.FindString(sel.Text()) == "" {
log.Println("unable to detect day of week")
return
}
p.detail[el].Day = sel.Text()
}
})
}
Expand Down
Loading