使用jsoup从网站网址中提取YouTube视频网址 [英] Extract a youtube video url from a site url using jsoup

查看:174
本文介绍了使用jsoup从网站网址中提取YouTube视频网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一网站上使用了此代码,但是他们改变了主题,现在我很挣扎. 在这里我要怎么做才能获取youtube视频的网址?这是我的方法.该站点的示例链接为 http://kabumbu.co.tz/mahojiano-na -masau-bwire/

I had this code working for the same site but they changed the theme and now i'm struggling. What could i be doing wrong here to get the url of the youtube video? Here's my approach. The example link of the site is http://kabumbu.co.tz/mahojiano-na-masau-bwire/

Element video = doc.select("div.single-archive iframe").first() ;
          videourl = video.attr("src");

推荐答案

到目前为止,该代码是正确的,但我只是错误地从视频网址中提取了视频ID.使用此方法有效

The code is correct so far but I just was wrongly extracting the video id from the video url. Using this method worked

public static String extractVideoId(String ytUrl) {
    String vId = null;
    Pattern pattern = Pattern.compile(".*(?:youtu.be\\/|v\\/|u\\/\\w\\/|embed\\/|watch\\?v=)([^#\\&\\?]*).*");
    Matcher matcher = pattern.matcher(ytUrl);
    if (matcher.matches()){
        vId = matcher.group(1);
    }
    return vId;
}

这篇关于使用jsoup从网站网址中提取YouTube视频网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆