From 62b628b2d0fb8d0c76592bcd5347e5bcec6106c4 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Fri, 13 Oct 2017 20:32:25 -0400 Subject: Improve search parse (#401) --- .../kotlin/com/pitchedapps/frost/parsers/SearchParser.kt | 15 +++++---------- app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt | 8 ++++++++ 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/parsers/SearchParser.kt b/app/src/main/kotlin/com/pitchedapps/frost/parsers/SearchParser.kt index 0d542a80..37c09299 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/parsers/SearchParser.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/parsers/SearchParser.kt @@ -47,23 +47,18 @@ private class SearchParserImpl : FrostParserBase>() { val container: Element = doc.getElementById("BrowseResultsContainer") ?: doc.getElementById("root") ?: return null - val hrefSet = mutableSetOf() /** - * When mapping items, some links are duplicated because they are nested below a main one - * We will filter out search items whose links are already in the list * * Removed [data-store*=result_id] */ return container.select("a.touchable.primary[href]").filter(Element::hasText).mapNotNull { - val item = FrostSearch(it.attr("href").formattedFbUrlCss, - it.select("._uok").first()?.text() ?: it.text(), - it.select("._1tcc").first()?.text()) - if (hrefSet.contains(item.href)) return@mapNotNull null - hrefSet.add(item.href) - item - } + FrostSearch(it.attr("href").formattedFbUrlCss, + it.select(".title").first()?.text() ?: "", + it.select(".subtitle").first()?.ownText()) + }.filter { it.title.isNotBlank() } } + override fun textToDoc(text: String): Document? = Jsoup.parse(text) override fun debugImpl(data: List, result: MutableList) { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt index 112269c1..6d6c5381 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Utils.kt @@ -32,6 +32,7 @@ import com.pitchedapps.frost.dbflow.CookieModel import com.pitchedapps.frost.facebook.* import com.pitchedapps.frost.utils.iab.IS_FROST_PRO import org.jsoup.Jsoup +import org.jsoup.nodes.Element import java.io.IOException import java.util.* @@ -223,3 +224,10 @@ fun frostJsoup(url: String) fun frostJsoup(cookie: String?, url: String) = Jsoup.connect(url).cookie(FACEBOOK_COM, cookie).userAgent(USER_AGENT_BASIC).get()!! +fun Element.first(vararg select: String): Element? { + select.forEach { + val e = select(it) + if (e.size > 0) return e.first() + } + return null +} \ No newline at end of file -- cgit v1.2.3