找不到:值UADetectorServiceFactory

时间:2014-05-21 07:23:54

标签: scala browser user-agent bots

在此question的引用上,我在Scala中尝试以下代码:

import net.sf.uadetector._
def check = Action { implicit request =>
    println(request.headers)
    var parser = UADetectorServiceFactory.getOnlineUpdatingParser();
    println(parser)
    val agent = parser.parse(request.headers.get("User-Agent").getOrElse(""))
    println(agent)
    val which = agent.getUserAgentType(); // this can be ROBOT, BROWSER, etc.
    println(which)
    Ok(write(Map("result" -> true)))
}

  

libraryDependencies + =“net.sf.uadetector”%“uadetector-core”%   “0.9.16”

但是我收到了一个错误:

not found: value UADetectorServiceFactory

var parser = UADetectorServiceFactory.getOnlineUpdatingParser();

             ^

我错过了什么吗?

2 个答案:

答案 0 :(得分:3)

  

我错过了什么吗?

是的,您已导入net.sf.uadetector个包裹中的所有内容,但UADetectorServiceFactory位于net.sf.uadetector.service

添加

import net.sf.uadetector.service.UADetectorServiceFactory

import net.sf.uadetector.service._

编译应该没问题

答案 1 :(得分:0)

  

我错过了什么吗?

是的,我得到了我所缺少的内容,但是getUserAgentType仍然没有工作,所以我用getType()代替了。{1}}。

import net.sf.uadetector.service._
import net.sf.uadetector._

def check = Action { implicit request =>
  var parser = UADetectorServiceFactory.getOnlineUpdatingParser()
  println(parser)
  val agent = parser.parse(request.headers.get("User-Agent").getOrElse(""))
  println(agent)
  val which = agent.getType()
  println(which)
  Ok(write(Map("result" -> true)))
}

并且需要两个库依赖项来运行上面的代码:

  • " net.sf.uadetector" %" uadetector-core" %" 0.9.16",

  • " net.sf.uadetector" %" uadetector-resources" %" 2013.04",