Android Jsoup:如何获取视频url?
我正在尝试从html解析视频url。我正在使用JSoupParse来解析它。我想解析Android Jsoup:如何获取视频url?,android,url,video,jsoup,html-parser,Android,Url,Video,Jsoup,Html Parser,我正在尝试从html解析视频url。我正在使用JSoupParse来解析它。我想解析 <meta property="og:video" content="http://video.foxnews.com/assets/video-player.swf?video_id=2475698001001&d=video.foxnews.com&auto_play=true"> 我的代码中应该更改什么 提前谢谢你 假设您正在使用asynctask/thread进行网络相关操
<meta property="og:video" content="http://video.foxnews.com/assets/video-player.swf?video_id=2475698001001&d=video.foxnews.com&auto_play=true">
我的代码中应该更改什么
提前谢谢你 假设您正在使用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");
String myhtml=”“;
Document doc=Jsoup.parse(myhtml);
元素eMETA=doc.select(“meta”).first();
字符串s=eMETA.attr(“内容”);
我将代码更改如下:
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();
}
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();
}