Android Web请求标题抓取

Android Web请求标题抓取,android,function,sdk,request,web,Android,Function,Sdk,Request,Web,你能帮我从这页抓取标题吗?例如:?我所说的标题是指小时表旁边的粗体文本。我需要抓取每个文本,然后把它放在设备的屏幕上。这是我的密码: package com.work.webrequest; import java.io.IOException; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.client.HttpClient; import org

你能帮我从这页抓取标题吗?例如:?我所说的标题是指小时表旁边的粗体文本。我需要抓取每个文本,然后把它放在设备的屏幕上。这是我的密码:

package com.work.webrequest;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class WebRequest extends Activity {


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String trax;
        String aux = "";

        setContentView(R.layout.main);
        TextView txt = (TextView) findViewById(R.id.textView1);
        trax=getPage();

       aux=title (trax);

        txt.setText(aux);

    }
    private String title (String trax)
    {
         String aux = "";
         int i,j,n;
         n=trax.length();
         for(i=1;i<=n;i++)
         {
            if(trax.charAt(i-1)=='2'&&trax.charAt(i)=='>')
            {
                break;
            }
         }
         for(j=i+1;j<=n;j++)
         {
            if(trax.charAt(j)=='<'&&trax.charAt(j+1)=='/')
            {
                break;
            }
         }
         System.out.println("n ESTE EGAL CU "+n+"i ESTE EGAL CU "+i+" SI j ESTE EGAL CU "+j);

         aux = trax.substring(i+1, j);
         return aux;
    }
    private String getPage() {
        String str = "***";

        try
        {
            HttpClient hc = new DefaultHttpClient();
            HttpPost post = new HttpPost("http://golfnews.no/golfpaatv.php");
            HttpResponse rp = hc.execute(post);

            if(rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
            {
                str = EntityUtils.toString(rp.getEntity());
            }
        }catch(IOException e){
            e.printStackTrace();
        }  

        return str;
    }


}

->我创建的函数private String title String trax不够好,因为它只获取第一个标题。。你能帮我推理一下吗,或者帮我做个更好的功能?谢谢

这是我第一次做这样的事。。。但不客气 顺便说一下,这是最糟糕的方法

private String[] title (String trax)
{
     String aux[] = trax.split("program-info");
     int n = aux.length;
     String[] result = new String[i=1];
     for(int i=1;i<=n;i++)
        result[i-1] = aux[i].subString(aux[i].indexOf("<h2>")+4,aux[i].indexOf("</h2>"));
     return result;
}

它只获取第一个标题,因为它只有一个字符串。你考虑过字符串数组吗?是的,我知道为什么它只获取第一个标题。如果我使用字符串数组,我将为它设置什么维度?标题的数量,从一天到另一天是不一样的。你能帮我举个函数例子吗?你能告诉我最简单的方法吗?我是个初学者,对安卓系统知之甚少。顺便说一句,这个函数不适合我。这是简单的java!aux必须是字符串[]而不是字符串,并且要获取您使用的所有标题,forint i=0;iYes,我理解你的功能,只是应用程序崩溃了,我不知道为什么…索引超出范围。。我尝试编辑注释已有一段时间了String[]result=new String[I=1];我是说n-1!