0

我正在尝试从一个网站获取特定标签。我可以阅读 HTML,但无法获取特定标签。有没有办法完成这个任务?我在其他线程中搜索,但找不到解决方案。

提前致谢。

这是代码。

    public class MainActivity extends Activity {

TextView text;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

text = (TextView)findViewById(R.id.text);

    DownloadTask task = new DownloadTask();
    task.execute("http://zodia.bg/sign/aries");

}

  private class DownloadTask extends AsyncTask<String, Void, String>{

    @Override
    protected String doInBackground(String... urls) {
        HttpResponse response = null;
        HttpGet httpGet = null;
        HttpClient mHttpClient = null;
        String s = "";

        try {
            if(mHttpClient == null){
                mHttpClient = new DefaultHttpClient();
            }


            httpGet = new HttpGet(urls[0]);


            response = mHttpClient.execute(httpGet);
            s = EntityUtils.toString(response.getEntity(), "UTF-8");


        } catch (IOException e) {
            e.printStackTrace();
        }


        return s;
    }

    @Override
    protected void onPostExecute(String result){


           text.setText(result);



    }
}

}

4

1 回答 1

0

您可以使用类似jsoup的 DOM 遍历,也可以手动使用字符串操作来查找所需内容并将其解析出来(substring()indexOf()等)

于 2013-10-08T19:24:35.793 回答