aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt35
1 files changed, 23 insertions, 12 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt
index b044ee58..e4339d4f 100644
--- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt
+++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/parsers/SearchParser.kt
@@ -76,22 +76,33 @@ private class SearchParserImpl : FrostParserBase<FrostSearches>(false) {
override var nameRes = FbItem._SEARCH.titleId
- override val url = "${FbItem._SEARCH.url}?q=a"
+ override val url = "${FbItem._SEARCH.url}?q=google"
override fun parseImpl(doc: Document): FrostSearches? {
val container: Element = doc.getElementById("BrowseResultsContainer")
?: doc.getElementById("root")
?: return null
- /**
- *
- * Removed [data-store*=result_id]
- */
- return FrostSearches(container.select("a.touchable[href]").filter(Element::hasText).map {
- FrostSearch.create(
- it.attr("href").formattedFbUrl,
- it.select("._uoi").first()?.text() ?: "",
- it.select("._1tcc").first()?.text()
- )
- }.filter { it.title.isNotBlank() })
+
+ return FrostSearches(container.select("table[role=presentation]").mapNotNull { el ->
+ // Our assumption is that search entries start with an image, followed by general info
+ // There may be other <td />s, but we will not be parsing them
+ // Furthermore, the <td /> entry wraps a link, containing all the necessary info
+ val a = el.select("td").getOrNull(1)?.selectFirst("a") ?: return@mapNotNull null
+ val url =
+ a.attr("href").takeIf { it.isNotEmpty() }?.formattedFbUrl ?: return@mapNotNull null
+ // Currently, children should all be <div /> elements, where the first entry is the name/title
+ // And the other entries are additional info.
+ // There are also cases of nested tables, eg for the "join" button in groups.
+ // Those elements have <span /> texts, so we will filter by div to ignore those
+ val texts = a.children().filter { it.tagName() == "div" && it.hasText() }
+ val title = texts.firstOrNull()?.text() ?: return@mapNotNull null
+ val info = texts.takeIf { it.size > 1 }?.last()?.text()
+ L.e { a }
+ create(
+ href = url,
+ title = title,
+ description = info
+ ).also { L.e { it } }
+ })
}
}