Diskuze: Android App
Zobrazeno 4 zpráv z 4.
1.) jde to, musíš vědět co v tom hledáš a púak to z toho stringu
dostat. Můžeš použít regulérní výrazy, substring, ...
2.) nauč se používat funkci vložit zdrojový kód (viz. obr)
Ok našiel som nejaký kód, konkrétne:
public class Bot {
public static void main(String[] args) throws IOException {
BufferedReader buff;
InputStreamReader inStream;
String htmlCode = null;
try{
URL url = new URL("http://rads.stackoverflow.com/amzn/click/473246031");
URLConnection urlConnection = (URLConnection)url.openConnection();
inStream = new InputStreamReader(urlConnection.getInputStream());
buff = new BufferedReader(inStream);
while(true){
if (buff.readLine()!=null){
htmlCode += buff.readLine() + "\n";
}else{
break;
}
}
int startFrom = htmlCode.indexOf("<div class=\"zg_rank\">");
int endFrom = htmlCode.indexOf("</div>");
String idNumber = htmlCode.substring(startFrom, endFrom);
System.out.println(idNumber);
}catch(Exception e){};
}
}
jediná chýba je že keď dám napr.:
int startFrom = htmlCode.indexOf("<title>");
int endFrom = htmlCode.indexOf("</title>", startFrom);
Tak toto idem až na to,že mi tam píše <title>[a Text].
No keď chcem vložiť len <div> s class, čo sa používa skoro všade
tak to nejde (keď dám napr.
<div class="nieco"><*b> a koniec <*/b></div>, tak
ide)
napr.:
int startFrom = htmlCode.indexOf("<div class=\"uvod\">");
int endFrom = htmlCode.indexOf("</div>", startFrom);
Tak potom mi tam nič nevypíše.
Síce z časti ale stále to ide len čisto cez Java a nie Android ale šak bolo písané, že to ide spustiť aj na Android (možno s malimi upravami).
Zobrazeno 4 zpráv z 4.