android - 在 Android 上解析 SHOUTcast 7.html 元数据

标签 android html parsing shoutcast

我正在尝试使用此 URL 检查 SHOUTcast 流的状态:

http://85.17.167.136:8684/7.html

...返回如下数据:

<HTML><meta http-equiv="Pragma" content="no-cache"></head><body>7,1,77,100,7,128,+44(0)7908 340 811 Follow Us @visionradiouk</body></html>

我知道,如果流已启动并正在运行,则第一个逗号之后返回 1,如果流已关闭,则返回 0。我的问题是获取该页面的 html?我使用此代码,它适用于 Google 等其他网站。

    TextView tView = (TextView) findViewById(R.id.textView1);


String htmlCode = "";

try {
    URL url = new URL("http://85.17.167.136:8684/7.html"); 
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));

    String inputLine;

    while ((inputLine = in.readLine())!= null)
        htmlCode += inputLine;
    System.out.println(htmlCode);
    tView.setText(htmlCode);
    in.close();     
} catch (Exception e){
    System.out.println("error");
}


}

对我做错了什么有什么想法吗?

最佳答案

这是 Pulsarman325 的工作解决方案,经过整理,我必须添加一些额外的东西才能让它工作(try/catch 和变量初始化)

String url = "http://molestia.ponify.me:8062";

URL url2=null;

try
{
    url2 = new URL(url + "/7.html");

}

catch (MalformedURLException e1)
{
    e1.printStackTrace();
}

URLConnection con=null;

try
{
    con = url2.openConnection();
}

catch (IOException e1)
{
  e1.printStackTrace();

}

con.setRequestProperty("User-Agent", "Mozilla/5.0");

Reader r = null;

try
{
    r = new InputStreamReader(con.getInputStream());
}

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

StringBuilder buf = new StringBuilder();

int ch=0;

while (true)
{
    try
    {
        ch = r.read(); 
    }

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

    if (ch < 0)
      break;

    buf.append((char) ch);

}

String str = buf.toString();

String trackinfo = str.split(",")[6].split("</body>")[0];

Log.d("HTML", trackinfo);

关于android - 在 Android 上解析 SHOUTcast 7.html 元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21767015/

相关文章:

javascript - 将多个表合并到一个数据库 SQLite

java - 在 Android 中使用 isReachable() 时出错

javascript - ImageFlow + HighSlide dimmingOpacity 选项

sql - 未知函数 'length' 位于/usr/lib/perl5/site_perl/5.8.5/SQL/Statement.pm 第 88 行

objective-c - 将 Plist (NSString) 解析为 NSDictionary

android - 插页式 Admob 广告 : "IllegalStateException: Only fullscreen activities can request orientation"

android - Appium 测试工具无法识别 ionic 应用程序中的元素 ID

javascript - jQuery 加载多个 ul 列表的前 3 个元素

JavaScript 函数未定义错误 onmouseover

java - 是否有 GSP(通用 SQL 解析器)的替代品?