나는 자바에 대해 매우 익숙하므로 코드가 좋지 않을 것이라는 것을 이해합니다. 그러나 나는 새로운 클래스 개체를 만들려고 while 루프를 사용하여 같은 1,2,3 등 변수로 누른 다음 그것은 게임 이름을 웹 사이트에서 당겨 후 것입니다. while 루프에서 다른 변수를 사용하여 클래스 객체 만들기
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
public class GameInformationPuller
{
public static void PullInformation() {
String gameName = "";
String gameRating = "";
String gameGenre = "";
int count = 0;
int i = 0;
StringBuilder sb = new StringBuilder();
GameInformation name;
boolean flag;
try {
URL url = new URL("http://www.mmorpg.com/gamelist.cfm/show/all/sCol/titleUC/sOrder/asc");
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
BufferedWriter writer = new BufferedWriter(new FileWriter("C:\\data4.txt"));
String line;
while ((line = reader.readLine()) != null)
{
if(line.contains("http://www.mmorpg.com/gamelist.cfm/game/") || line.contains("<span class=\"value rating\">") || line.contains("title=\"Not enough votes to tabulate\">") || line.contains("<td class=\"genre\">"))
{
if(!line.contains("Jump to Random Game"))
{
sb.delete(0, sb.length());
//------------------------------------------------
if(line.contains("http://www.mmorpg.com/gamelist.cfm/game/"))
{
flag = false;
count = 0;
i = 0;
while(i < line.length() - 1 && flag == false)
{
if(count >= 2 && flag == false)
{
if(line.charAt(i) == '<')
{
flag = true;
}
else
{
if(!(line.charAt(i) == '.'))
{
sb.append(line.charAt(i));
gameName = new String(sb);
}
}
}
if(line.charAt(i) == '>')
{
count++;
}
i++;
}
}
//------------------------------------------------
name = new GameInformation(gameName);
}
//------------------------------------------------
}
else
{
//Nothing
}
}
}
//Close reader and writer
reader.close();
writer.close();
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
내가 그것을이 부분에서 발견 각 게임 이름에 대한 새로운 변수합니다 : 이름을 = 새로운 GameInformation (gameName); 희망적이라고 생각합니다.
감사 사이먼
: // 소풍-API를 .com /) 웹 사이트를 긁어 정보를 얻으려면. –
그냥 구문 트릭입니다 :'flag == false'는 꽤 흔하지 않습니다.'! flag'는 글자를 쓰는 것이 더 짧습니다. (그리고 제 생각에는 더 읽기 쉽습니다) :) – NiziL
미래에이 팁들을 기억하십시오 :) 나는 아직도 사용하는 것 같습니다. 이전 VB 방식으로 LOL – user3568925