inital commit
This commit is contained in:
38
search_parser.go
Normal file
38
search_parser.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package fa
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
)
|
||||
|
||||
// parseSearchResults walks /search/ output, returning each result and
|
||||
// whether a "Next" page link exists.
|
||||
//
|
||||
// FA renders results inside <section id="gallery-search-results"> with the
|
||||
// same <figure id="sid-…"> shape as gallery/browse/inbox, so the per-item
|
||||
// extraction reuses parseGalleryFigure. Pagination is page-numbered (GET
|
||||
// ?page=N) and the Next anchor is in <div class="pagination"> at the top
|
||||
// (and bottom) of the results.
|
||||
//
|
||||
// useJSON controls the experimental JSON-first merge see parseGalleryPage.
|
||||
func parseSearchResults(doc *goquery.Document, useJSON bool) (items []*Submission, hasNext bool) {
|
||||
var jsonData listingJSONMap
|
||||
if useJSON {
|
||||
jsonData = readListingJSON(doc)
|
||||
}
|
||||
doc.Find("section#gallery-search-results figure[id^=sid-]").Each(func(_ int, sel *goquery.Selection) {
|
||||
if s := parseGalleryFigure(sel, jsonData); s != nil {
|
||||
items = append(items, s)
|
||||
}
|
||||
})
|
||||
|
||||
doc.Find("div.pagination a.button").EachWithBreak(func(_ int, a *goquery.Selection) bool {
|
||||
if strings.EqualFold(trimText(a), "next") {
|
||||
hasNext = true
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
return items, hasNext
|
||||
}
|
||||
Reference in New Issue
Block a user