refactor: deduplicate numericOnly and DuckDuckGo result extraction
- Extract identical numericOnly inline functions from powerball and megamillions into shared sites/internal/parse.NumericOnly with tests - Extract duplicated DuckDuckGo result parsing from Search() and GetResults() into shared extractResults() helper Closes #13, #14 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,9 +18,14 @@ type searchPage struct {
|
||||
}
|
||||
|
||||
func (s searchPage) GetResults() ([]Result, error) {
|
||||
return extractResults(s.doc)
|
||||
}
|
||||
|
||||
// extractResults parses search results from a DuckDuckGo results page.
|
||||
func extractResults(doc extractor.Node) ([]Result, error) {
|
||||
var res []Result
|
||||
|
||||
err := s.doc.ForEach(`article[id^="r1-"]`, func(n extractor.Node) error {
|
||||
err := doc.ForEach(`article[id^="r1-"]`, func(n extractor.Node) error {
|
||||
var r Result
|
||||
|
||||
links := n.Select(`a[href][target="_self"]`)
|
||||
|
||||
Reference in New Issue
Block a user