当前位置: 首页>>代码示例>>Scala>>正文


Scala Elements类代码示例

本文整理汇总了Scala中org.jsoup.select.Elements的典型用法代码示例。如果您正苦于以下问题:Scala Elements类的具体用法?Scala Elements怎么用?Scala Elements使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Elements类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: HtmlLifter

//设置package包名称以及导入依赖的类
package com.twitter.diffy.lifter

import org.jsoup.Jsoup
import org.jsoup.nodes.{Document, Element}
import org.jsoup.select.Elements

import scala.collection.JavaConversions._

object HtmlLifter {
  def lift(node: Element): FieldMap[Any] = node match {
    case doc: Document =>
      FieldMap(
        Map(
          "head" -> lift(doc.head),
          "body" -> lift(doc.body)
        )
      )
    case doc: Element => {
      val children: Elements = doc.children
      val attributes =
        FieldMap[String](
          doc.attributes.asList map { attribute =>
            attribute.getKey -> attribute.getValue
          } toMap
        )

      FieldMap(
        Map(
          "tag"         -> doc.tagName,
          "text"        -> doc.ownText,
          "attributes"  -> attributes,
          "children"    -> children.map(element => lift(element))
        )
      )
    }
  }

  def decode(html: String): Document = Jsoup.parse(html)
} 
开发者ID:sachinmanchanda,项目名称:diffy_unicast,代码行数:40,代码来源:HtmlLifter.scala

示例2: JsoupHelper

//设置package包名称以及导入依赖的类
package util

import java.util.stream.Collectors

import org.jsoup.nodes.Element
import org.jsoup.select.Elements


object JsoupHelper {
  implicit def elementsToElements4Scala(elements: Elements): Elements4Scala = {
    new Elements4Scala(elements)
  }
}

class Elements4Scala(that: Elements) {
  def toElementArray: Array[Element] = {
    val list: java.util.List[Element] = that.stream.collect(Collectors.toList[Element])
    list.toArray(new Array[Element](list.size()))
  }
} 
开发者ID:ktr-skmt,项目名称:FelisCatusZero,代码行数:21,代码来源:JsoupHelper.scala

示例3: TorrentSearchResult

//设置package包名称以及导入依赖的类
package providers

import org.jsoup.Jsoup
import org.jsoup.nodes.Element
import org.jsoup.select.Elements
import play.api.libs.json.Json
import play.api.libs.ws.WSClient


import scala.collection.JavaConversions._
import scala.concurrent.ExecutionContext.Implicits.global





case class TorrentSearchResult(name:String,magnetLink:String,
                               size:String,age:String,
                               seeders:String, leechers:String,
                               provider:String) extends SearchResult
object TorrentSearchResult{
  implicit val torrentSearchResultWrites = Json.writes[TorrentSearchResult]
}

class KatcrProvider extends SearchProvider {
  override def search(searchString:String, ws: WSClient, numberofResulstToReturn:Int) = {
    val searchProviderURL = "https://kat.cr/usearch/"
    ws.url(searchProviderURL + searchString).get().map {
      response => { //process the response
         extractTopTorrents(response.body,numberofResulstToReturn)
      }
    }
  }

  def processKatcrTableRow(tds: Elements):TorrentSearchResult =
    TorrentSearchResult(tds(0).text,
      tds.select("a[title=\"Torrent magnet link\"]").first().attr("href"),
      tds(1).text,
      tds(2).text,tds(3).text,tds(4).text, "kat.cr")


  def extractTopTorrents(htmlString:String, numberOfResults:Int) = {
    val tables:Elements = Jsoup.parse(htmlString).select("table")
    val table = tables.get(1)
    // Get the top numberOfResults and the return a list of TorrentSearchResult..
    table.select("tr").slice(1,numberOfResults+1).foldLeft(List[TorrentSearchResult]()){
      (result,tr) => // process each tr element and prepend to result
        processKatcrTableRow(tr.select("td")) :: result
    }
  }.reverse //since the list is sorted in the reverse seeders order
  .asInstanceOf[List[SearchResult]]
} 
开发者ID:aashiks,项目名称:jIgor,代码行数:53,代码来源:KatcrProvider.scala


注:本文中的org.jsoup.select.Elements类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。