2

My question is the same as this one except that instead of a single Document I have an array (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.

The solution for the case of a single Document object was:

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.

Community
  • 1
  • 1
Hack-R
  • 22,422
  • 14
  • 75
  • 131

2 Answers2

1

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

String[] result = new String[strvec.length];
    for(int n=0; n < strvec.length;n++)
      result[n]=Jsoup.connect(strvec[n]).get().html();
Hack-R
  • 22,422
  • 14
  • 75
  • 131
Dev. Joel
  • 1,127
  • 1
  • 9
  • 14
0
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.

  • Thank you. It didn't give an error in the IDE when I pasted that in, but when I tried to run it it threw this error on the last line of that codeblock `Exception in thread "main" java.lang.NullPointerException` – Hack-R Sep 12 '16 at 01:15