2013-10-08 109 views
0

我试图从一个网站获取特定的标签。 我可以阅读HTML,但无法获取特定的标签。 有什么办法可以做这个任务吗? 我在其他线程中搜索,但我找不到解决方案。android:如何从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); 



    } 
} 

}

回答

0

您可以使用DOM遍历的东西,如jsoup或者您也可以手动使用字符串操作来找到你所需要的,并解析出来(substring()indexOf()等)