Refresh.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const axios = require("axios");
  2. const cheerio = require('cheerio');
  3. const fs = require("fs");
  4. module.exports = Refresh;
  5. var json = [];
  6. async function get_next(url) {
  7. var res = await axios.get(url=url, {
  8. headers: {
  9. 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
  10. }
  11. })
  12. var $ = cheerio.load(res.data);
  13. var article = $('.post-box-list article');
  14. for (var i=0; i<article.length; i++) {
  15. var url = article.eq(i).attr('data-href');
  16. var img_url = /\((.*)\)/g.exec($('.post-box-image', article.eq(i)).attr('style'))[1];
  17. var meta = $('.post-box-meta', article.eq(i)).text();
  18. var title = $('.post-box-title', article.eq(i)).text();
  19. json.push({
  20. title: title,
  21. meta: meta,
  22. url: url,
  23. img_url: img_url
  24. })
  25. }
  26. console.log(`当前页: ${$('.page-numbers.current').text()}`);
  27. return $('.next.page-numbers').attr('href');
  28. }
  29. async function Refresh() {
  30. var url = "https://ddrk.me/";
  31. var i = 0;
  32. do {
  33. url = await get_next(url.toString());
  34. i += 1;
  35. } while (url != undefined);
  36. $ui.toast("刷新成功");
  37. $storage.put("videos", json);
  38. }