質問

I am trying to parse video url from html. I am using Jsoup parse to parse it. I want to parse

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

from this html. How can i get this content from the above line.

Now my code is:

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

What should change in my code?

Thank you in advance!

役に立ちましたか?

解決 2

I changed my code as follows:

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

        }

他のヒント

Assuming you are using asynctask/thread for network related operation.

Assuming its the first meta you can do as below

 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"); 
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top