perbaiki kode js berikut di scraperconst axios = requireaxios;const cheerio = requirecheerio;async function ttdownUrl try const respon = await axiosgethttpsttdownloadercom headers
Berikut adalah kode yang telah diperbaiki:
const axios = require('axios'); const cheerio = require('cheerio');
async function ttdown(Url) { try { const respon = await axios.get("https://ttdownloader.com/", { headers: { "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9", "accept-language": "en-US,en;q=0.9,id;q=0.8", "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36", "cookie": "_ga=GA1.2.1240046717.1620835673; PHPSESSID=i14curq5t8omcljj1hlle52762; popCookie=1; _gid=GA1.2.1936694796.1623913934" } });
const $ = cheerio.load(respon.data);
const token = $('#token').attr('value');
const res = await axios.get("https://ttdownloader.com/", {
method: "get",
params: {
url: Url,
format: "",
token: token
},
headers: {
"accept": "*/*",
"accept-language": "en-US,en;q=0.9,id;q=0.8",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
"cookie": "_ga=GA1.2.1240046717.1620835673; PHPSESSID=i14curq5t8omcljj1hlle52762; popCookie=1; _gid=GA1.2.1936694796.1623913934"
}
});
const ch = cheerio.load(res.data);
const result = {
status: res.status,
result: {
nowatermark: await shortlink(ch('#results-list .result > div:nth-child(2)').find('div.download-link').attr('href')),
watermark: await shortlink(ch('#results-list .result > div:nth-child(3)').find('div.download-link').attr('href')),
audio: await shortlink(ch('#results-list .result > div:nth-child(4)').find(' div.download-link').attr('href'))
}
};
console.log(result);
return result;
} catch (error) { throw error; } }
async function shortlink(url) {
try {
const response = await axios.get(https://tinyurl.com/api-create.php?url=${encodeURIComponent(url)});
return response.data;
} catch (error) {
throw error;
}
}
ttdown('https://vm.tiktok.com/ZGJAmhSrp/'
原文地址: http://www.cveoy.top/t/topic/hYot 著作权归作者所有。请勿转载和采集!