在操场上进口Kanna [英] Import Kanna in playground

查看:275
本文介绍了在操场上进口Kanna的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法添加Kanna(

解决方案

Github中有一个有趣的库允许在Playground中运行pods它还很年轻,但非常好。它创建了一个安装了pod或pod并准备在Playground中测试的新项目。





我在您的图书馆测试过并且工作正常:

  //:请首先构建方案'KannaPlayground'
导入XCPlayground
XCPlaygroundPage.currentPage。 needsIndefiniteExecution = true

import Kanna

let html =< html>< a> Hello World< / a>< / html>

if let doc = Kanna.HTML(html:html,encoding:NSUTF8StringEncoding){
print(doc.title)

//通过CSS搜索节点
for doc.css中的链接(a,link){
print(link.text)
print(link [href])
}

//通过XPath
搜索doc.xpath中的链接(// a | // link){
print(link.text)
print(link [href])
}
}

我希望这有助于你。


Is there a way to add Kanna (https://github.com/tid-kijyun/Kanna) to Playground in XCode? I have tried to install it manually and via CocoaPods, but with no luck. I have also tried to pack it inside a Framework, but still no luck. Would appreciate any input.

These are the error messages I am most often encountering:

解决方案

There is an interesting library in Github that allows run pods in Playground.It's still so young but it's very good. It's create a new project with the pod or pods installed and ready to test in the Playground.

I tested with your library and works fine:

//: Please build the scheme 'KannaPlayground' first
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true

import Kanna

let html = "<html><a>Hello World</a></html>"

if let doc = Kanna.HTML(html: html, encoding: NSUTF8StringEncoding) {
  print(doc.title)

  // Search for nodes by CSS
  for link in doc.css("a, link") {
      print(link.text)
      print(link["href"])
  }

  // Search for nodes by XPath
  for link in doc.xpath("//a | //link") {
     print(link.text)
     print(link["href"])
  }
}

I hope this help you.

这篇关于在操场上进口Kanna的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆