简体   繁体   English

android:如何从html获取标签

[英]android:how to get tag from html

I'm trying to get specific tag from one web site. 我正在尝试从一个网站获取特定标签。 I can read the HTML but can't get the specific tag. 我可以阅读HTML,但无法获取特定标签。 Is there any way to do this task? 有什么办法可以完成这项任务? I was searching in other threads but I could not find the solution. 我在其他线程中搜索,但找不到解决方案。

Thanks in advance. 提前致谢。

Here is the code. 这是代码。

    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);



    }
}

} }

您可以对jsoup之类的东西使用DOM遍历,也可以手动使用String操作查找所需内容并解析出来( substring()indexOf()等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM