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

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

问题描述

我让这段代码在同一个网站上工作,但他们改变了主题,现在我很挣扎.我在获取 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");

推荐答案

到目前为止代码是正确的,但我只是错误地从视频 url 中提取了视频 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 从站点 url 中提取 youtube 视频 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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