0

我正在尝试从 html 解析视频 url。我正在使用 Jsoup 解析来解析它。我要解析

<meta property="og:video" content="http://video.foxnews.com/assets/video-player.swf?video_id=2475698001001&d=video.foxnews.com&auto_play=true">

这个 html。我如何从上面的行中获取此内容。

现在我的代码是:

try {
            Connection.Response response = Jsoup
                    .connect(htmlUrl)
                    .userAgent(
                            "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21")
                    .timeout(10000).execute();

            int statusCode = response.statusCode();
            Log.d("TAG", " status code is: " + statusCode);
            if (statusCode == 200) {
                doc = Jsoup.connect(htmlUrl).timeout(1000 * 100).get();
                Log.d("TAG","Document is created : " +  doc );
                Elements element = doc.select("meta");
                for (Element urls : element) {
                    //System.out.println(urls.text());
                    Log.d("TAG", " url is: " + urls.attr("property") + " " + urls.attr("og:video"));
                }
            } else {
                System.out.println("received error code : " + statusCode);
            }

我的代码应该改变什么?

先感谢您!

4

2 回答 2

2

假设您正在使用 asynctask/thread 进行网络相关操作。

假设它是第一个元数据,您可以执行以下操作

 String myhtml ="<meta property="+"og:video" +" "+"content="+"http://video.foxnews.com/assets/video-player.swf?video_id=2475698001001&d=video.foxnews.com&auto_play=true"+">";
 Document doc = Jsoup.parse(myhtml);  
 Element eMETA = doc.select("meta").first();
 String s = eMETA.attr("content"); 
于 2013-06-14T07:06:59.237 回答
0

我改变了我的代码如下:

try {
            Connection.Response response = Jsoup
                    .connect(htmlUrl)
                    .userAgent(
                            "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21")
                    .timeout(1000000).execute();

            int statusCode = response.statusCode();
            Log.d("TAG", " status code is: " + statusCode);
            if (statusCode == 200) {
                doc = Jsoup.connect(htmlUrl).timeout(1000 * 1000).get();
                Elements meta = doc.select("meta[property=og:video]");

                for (Element src : meta) {
                    if (src.tagName().equals("meta"))
                        Log.d("TAG", " content: " + src.attr("content"));
                    else
                        Log.d("TAG", src.tagName());
                }
            } else {
                System.out.println("received error code : " + statusCode);
            }
        } catch (IOException e) {
            Log.d("TAG", " Exception " + e);
            e.printStackTrace();

        }
于 2013-06-14T08:45:53.133 回答