package tv;
import java.io.*;
import java.net.URLEncoder;
public class pro {
int s,datanumber;
String[] data=new String[5000];
int number;
String[] dic=new String[5000];
String[] codex=new String[5000];
public static void main(String[] args) {
pro r=new pro();
}
pro(){
readx("data.txt");
int tr;
for(tr=1;tr<number+1;tr++){
String de=dic[tr];
String word="";
try {
word= URLEncoder.encode(de, "SJIS");;
} catch (UnsupportedEncodingException e) {
System.err.println(e.getMessage());
}
System.out.println(word);
String urlx="http://www.oricon.co.jp/search/result.php?types=artist&search_string="+word;
getdata sub=new getdata();
sub.makedata(urlx,"SJIS");
datanumber=sub.datanumber;
data=sub.data;
String code="";
for(s=1;s<datanumber+1;s++){
if(data[s].indexOf("/prof/")>-1)code=data[s];
}
int p1=code.indexOf("prof/");
p1=code.indexOf("/",p1);
int p2=code.indexOf("/",p1+1);
if(p1>-1)code=code.substring(p1+1,p2);
codex[tr]=code;
}
writexml("code.txt");
}
void writexml(String file){
int s,sx;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
for(s=1;s<number+1;s++){
pw.println(codex[s]);
}
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
void readx(String file){
String str;
BufferedReader br;
int s;
s=0;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
while((str = br.readLine()) != null) {
s=s+1;
dic[s]=str;
}
br.close();
} catch (IOException e) {System.out.println(e);}
number=s;
}
}
package tv;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.HttpURLConnection;
public class getdata {
int s,datanumber;
String[] data=new String[500000];
void makedata(String urlx,String code){
try {
URL connectUrl = new URL(urlx);
HttpURLConnection con = (HttpURLConnection)connectUrl .openConnection();
con.setRequestMethod("GET");
con.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream(), code));
s=0;
String line;
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
s=s+1;
data[s]=line;
}
datanumber=s;
reader.close();
con.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
}
最終更新:2017年04月14日 20:06