Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何将scala中的元素拆分为字符串数组_Arrays_Scala_Jsoup - Fatal编程技术网

Arrays 如何将scala中的元素拆分为字符串数组

Arrays 如何将scala中的元素拆分为字符串数组,arrays,scala,jsoup,Arrays,Scala,Jsoup,我在将一个元素(从web上刮下来的)分割成一个字符串数组时遇到了一些麻烦 这是我的密码: link = "http://www.myurl.com" val doc: Document = Jsoup.connect(link).get() val title2 = doc.select("li > h3 > a").toString 这给了我: <a href="/association/129033/69-1ere-compagnie-d-arc-du-dauphine.

我在将一个元素(从web上刮下来的)分割成一个字符串数组时遇到了一些麻烦

这是我的密码:

link = "http://www.myurl.com"
val doc: Document = Jsoup.connect(link).get()
val title2 = doc.select("li > h3 > a").toString
这给了我:

<a href="/association/129033/69-1ere-compagnie-d-arc-du-dauphine.htm">1ERE COMPAGNIE D'ARC DU DAUPHINÉ</a>
<a href="/association/129512/69-38sms.htm">38SMS</a>
<a href="/association/128940/69-40-batteurs.htm">40 BATTEURS</a>
<a href="/association/129543/69-4l-four-liberty.htm">4L FOUR LIBERTY</a>
<a href="/association/129820/69-a-bord-perdu.htm">A BORD PERDU</a>

我想要的是在字符串数组中只包含href。仅接受“”中的字符串

我曾尝试使用像asScala这样的JavaConverter,但我正在使用它:/


谢谢

只需从a中提取href属性,您就可以得到如下结果:

doc.select("li > h3 > a").map(link -> link.attr("href")).toArray

看看从Jsoup中提取更多属性的功能

您的意思是:
doc.select(“li>h3>a”).map(doc->doc.attr(“href”).toArray
?另外,map出现错误(map不是org.jsoup.Elements的成员)我不知道如何测试它,但尝试一下这个->
doc.select(“li>h3>a”).asScala.map(doc->doc.attr(“href”).toArray
。让我知道它有帮助