diff options
author | Dmitry Ilvokhin <d@ilvokhin.com> | 2025-07-26 20:12:44 +0100 |
---|---|---|
committer | Dmitry Ilvokhin <d@ilvokhin.com> | 2025-07-26 20:12:44 +0100 |
commit | 2c525c56625e4ae9429147d17808b5422353562c (patch) | |
tree | 2d2e6b4d034f1e2d7c9df108bff41b9fb6bff73d /parse.go | |
parent | 2382010abc8e879ea8e665839c76e87f8db0fa40 (diff) | |
download | flatbot-2c525c56625e4ae9429147d17808b5422353562c.tar.gz flatbot-2c525c56625e4ae9429147d17808b5422353562c.tar.bz2 flatbot-2c525c56625e4ae9429147d17808b5422353562c.zip |
Properly extend parser to parse properties for sale
Previous commit had only test files, but not actual code changes.
Diffstat (limited to 'parse.go')
-rw-r--r-- | parse.go | 30 |
1 files changed, 23 insertions, 7 deletions
@@ -40,9 +40,18 @@ func findNodes(root *html.Node) []*html.Node { if n.Data != "a" { continue } + // Try to match attribute for let. attr := matchAttr(n, "data-testid") if attr == nil || attr.Val != "property-price" { - continue + // If unsuccessful, try to match attribute for buy. + attr = matchAttr(n, "data-test") + if attr == nil || attr.Val != "property-header" { + continue + } + href := matchAttr(n, "href") + if href == nil || href.Val == "" { + continue + } } flats = append(flats, n) } @@ -73,17 +82,24 @@ func parseNode(root *html.Node) (flat, error) { f.Price = price return f, nil } + if strings.HasPrefix(n.Data, "£") { + f.Price = strings.TrimSpace(n.Data) + return f, nil + } } return flat{}, errors.New("Couldn't find price") } func parseID(path string) (int, error) { s, _ := strings.CutPrefix(path, "/properties/") - maybeID, _ := strings.CutSuffix(s, "#/?channel=RES_LET") - ID, err := strconv.Atoi(maybeID) - if err != nil { - err := fmt.Errorf("Couldn't extract ID from %q", path) - return -1, err + for _, channel := range []string{"LET", "BUY"} { + suffix := fmt.Sprintf("#/?channel=RES_%v", channel) + maybeID, _ := strings.CutSuffix(s, suffix) + ID, err := strconv.Atoi(maybeID) + if err == nil { + return ID, nil + } } - return ID, err + err := fmt.Errorf("Couldn't extract ID from %q", path) + return -1, err } |