c++ - 网页加载时获取m3u8资源的url

标签 c++ web-scraping html libcurl

我正在编写一个程序,让用户输入带有视频的网页的 url。该程序将采用它并关闭该网站。然后该程序将从该网站提取 m3u8 链接并将其返回。

根据我的研究,获取网页的最佳方式似乎是使用 curl。我的问题是,一旦我有了网页,我如何找到该特定 Assets ?

最佳答案

A similar question has been asked before .发布问题的用户询问如何下载视频并关闭它。工作代码已发布,但随后被删除。

这是工作代码[使用 libcurl/c++ 等]:

#define CURL_STATICLIB
#include <stdio.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
#include <string>

size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
    size_t written;
    written = fwrite(ptr, size, nmemb, stream);
    return written;
}

int main(void) {
    CURL *curl;
    FILE *fp;
    CURLcode res;
    char *url = "http://localhost/aaa.txt";
    char outfilename[FILENAME_MAX] = "C:\\bbb.txt";
    curl = curl_easy_init();
    if (curl) {
        fp = fopen(outfilename,"wb");
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
        fclose(fp);
    }
    return 0;
}

还有 libcurl site还有其他您可能会觉得有用的示例代码。

希望对你有帮助

关于c++ - 网页加载时获取m3u8资源的url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53974755/

相关文章:

c++ - 从另一个模板类实例创建模板类实例时省略模板参数

c++ - 使用提示将排序范围插入 std::set

python - 循环运行 scrapy 任务

python - 无法使用 scrapy 使用此代码提取任何数据

excel - 从html中获取属性字符串值

javascript - 将html表单中的数据存储到excel表格中?

javascript - 我如何使用 HTML5 localStorage 之类的东西,但在浏览器之间共享?

c++ - 布局中带有 Qlabel 的 QT 显示图像不起作用

javascript - SVG 文本元素未在 IE 中添加

c++ - 如何修复我的 strcat 函数中的错误