简体   繁体   English

如何将 Jsoup Document[] 数组转换为 String[]?

[英]How can I convert a Jsoup Document[] array to a String[]?

My question is the same as this one except that instead of a single Document I have an array ( Document[] ).我的问题与相同,只是我有一个数组( Document[] )而不是单个Document

I normally use R, not Java, so I apologize if it should be apparent how to change the solution from the linked thread for the case of an array.我通常使用 R,而不是 Java,所以如果对于数组的情况下如何从链接线程更改解决方案应该很明显,我深表歉意。

The solution for the case of a single Document object was:对于单个Document对象的情况的解决方案是:

String htmlString = doc.html();

My code to create the object was:我创建对象的代码是:

Document[] target = new Document[20];
for(int n=0; n < strvec.length;n++){
    target[n] = Jsoup.connect(strvec[n]).get();
 }

I tried a few things like creating the original target object as String[] , putting .toString() on the end of Jsoup.connect(strvec[n]).get() and elsewhere, but these attempts were unsucessful.我尝试了一些事情,比如将原始target对象创建为String[] ,将.toString()放在Jsoup.connect(strvec[n]).get()和其他地方的末尾,但这些尝试都没有成功。

it is assumed that serves is an array of String containing the URL to connect, you do not need to create another array of Document假设服务是一个包含要连接的 URL 的字符串数组,您不需要创建另一个文档数组

String[] result = new String[strvec.length];
    for(int n=0; n < strvec.length;n++)
      result[n]=Jsoup.connect(strvec[n]).get().html();
String[] htmlList = new String[target.length];
for(int i = 0; i < target.length; i++)
    htmlList[i] = target[i].html();

This loop should do what you want.这个循环应该做你想做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM