Help please!
unknown error
You input any youtube comment page (after you click see all(comments) on a youtube video) e.g
http://www.youtube.com/all_comments?v=pGRPWJ5Ni1U
Then you input the number of comment pages, the number of pages at the bottom of the screen. e.g
3
It then grabs the HTML of the first page, selects all the lines with usernames in it, cuts off everything else apart from usernames. Then checks if there are any duplicates. Then it outputs all the usernames.
I ran the code and entered the number of pages = 1 so only names of the first page were read out, it worked fine. For number of pages = 2 it also worked.
But when number of pages = 3 it throws an error. Then outputs some names.
What is this error?
Plus it's checking pages 1 and 2 quite quickly about 6-8 seconds per page, but when checking up to page 3 it takes ages like 2-3 minutes.
import java.util.*;
import java.net.*;
import java.io.*;
public class Youtube {
public static void main(String args[]){
String video;
String comment;
int number = 0;
InputStream is = null;
String line;
URL page;
boolean check = false;
int namepos1;
int namepos2;
int reply;
char lessthan = '<';
List<String> names = new ArrayList<String>();
Scanner input = new Scanner(System.in);
System.out.println("Please enter the 1st Youtube comment page URL:");
video = input.nextLine();
System.out.println("Please enter the total number of comments:");
double comments = input.nextInt();
int pages = (int) Math.ceil( comments / 500d );
number++;
comment = video + "&page=" + number;
try{
while(number <= pages){
number++;
page = new URL(comment);
is = page.openStream();
BufferedReader d= new BufferedReader(new InputStreamReader(is));
while ((line = d.readLine()) != null){
if(check){
namepos1 = line.indexOf("yt-user-name ");
namepos2 = line.lastIndexOf(lessthan);
reply = line.indexOf("in reply to");
if(namepos1 > 0 && namepos2 > 0 && reply < 0){
int back=line.lastIndexOf("<");
int front=line.indexOf("yt-user-name ") + 25;
String aaa=line.substring(front , back);
if(!names.contains(aaa)) names.add(aaa);
System.out.println("Found Unique Username");
}else{}
check = false;
}
if(line.indexOf("author ") != -1) check = true;
}
comment = video + "&page=" + number;
}
System.out.println("List Of Unique UserNames:");
for(String name: names){
System.out.println(name);
}
}
catch (MalformedURLException mue) {
mue.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
Error
java.io.IOException: Premature EOF at sun.net.www.http.ChunkedInputStream.readAheadBlocking(Unknown Source) at sun.net.www.http.ChunkedInputStream.readAhead(Unknown Source) at sun.net.www.http.ChunkedInputStream.read(Unknown Source) at java.io.FilterInputStream.read(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(Unknown Source) at sun.nio.cs.StreamDecoder.readBytes(Unknown Source) at sun.nio.cs.StreamDecoder.implRead(Unknown Source) at sun.nio.cs.StreamDecoder.read(Unknown Source) at java.io.InputStreamReader.read(Unknown Source) at java.io.BufferedReader.fill(Unknown Source) at java.io.BufferedReader.readLine(Unknown Source) at java.io.BufferedReader.readLine(Unknown Source) at Youtube.main(Youtube.java:40)
My coding may be bad, im new to Java xD.






Cartoon Clouds
Mountains
Sunrise
Clouds
Green Clouds
None

















Help