之前抖音的视频的下载地址是写在页面里的,不知道什么时候改成异步请求了 ,写到最后发现烂尾了 ,如果用c++来执行js获取token那就太费劲了,这事还是交给python干合适。但是代码写都写了也别浪费,留在这里以后没准能用上
#include <iostream>
#include <fstream>
#include <string>
#include "cpr/cpr.h"
int main(int argc, char* argv[]) {
if (argc < 3 || std::string(argv[1]) != "-c") {
std::cout << "Usage: " << argv[0] << " -c <cookie_file_path> <url>" << std::endl;
return 1;
}
std::string cookie_file_path = argv[2];
std::ifstream cookie_file(cookie_file_path);
if (!cookie_file.is_open()) {
std::cerr << "Failed to open cookie file: " << cookie_file_path << std::endl;
return 1;
}
std::string cookie_value;
std::getline(cookie_file, cookie_value);
cookie_file.close();
std::string url = argv[3];
std::cout << "URL: " << url << std::endl;
cpr::Header header = cpr::Header{
{"accept", "text/html"},
{"accept-encoding", "br"},
{"referer", "https://www.douyin.com/"},
{"cookie", "a"},
{"user-agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"}};
cpr::Response r = cpr::Get(cpr::Url{ url }, cpr::Header{header});
std::cout << "URL: " << r.text << std::endl;
return 0;
}
标签:写个,argc,int,argv,音视频,cpr,include,下载
From: https://www.cnblogs.com/netstat/p/18202151