Auto.js 获取小红书笔记信息(标题、介绍、图片)
搬运素材时要改写文案,此处Auto.js接入调用文心一言自动修改小红书标题,后续可将文案使用Auto.js自动化填写发布!
我直接贴出调用文心一言改写文案代码:
function getUrl(arg) {
const reg = /(https?|http|ftp|file):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/g;
arg = arg.match(reg);
if (arg && arg.length > 0) {
return arg[0];
}
return null;
}
function extractOGImageLinks(htmlText) {
const regex = /<meta name="og:image" content="([^"]+)"/g;
const matches = [];
let match;
while ((match = regex.exec(htmlText))!== null) {
matches.push(match[1]);
}
return matches;
}
function jeixixhsurl(url) {
var res = http.get(url);
var data = res.body.string();
var responseText = data; // 这里应该是从网络获取的实际响应文本
const images = extractOGImageLinks(responseText);
// 使用正则表达式提取信息(与 Python 脚本相同)
// var imageUrlsWebp = responseText.match(/http:\/\/sns-webpic-qc\.xhscdn\.com\/(.*?)!nd_dft_wlteh_webp_3">/g);
// var imageUrlsJpg = responseText.match(/http:\/\/sns-webpic-qc\.xhscdn\.com\/(.*?)!nd_dft_wlteh_jpg_3">/g);
// var images = [];
// var imageRegex = /http:\/\/sns-webpic-qc\.xhscdn\.com\/(.*?)!/;
// if (imageUrlsWebp) {
// imageUrlsWebp.forEach(function (url) {
// var match = url.match(imageRegex);
// if (match) {
// var fullUrl = "http://sns-webpic-qc.xhscdn.com/" + match[1] + "!nd_dft_wlteh_webp_3";
// images.push(fullUrl);
// }
// });
// }
// if (imageUrlsJpg) {
// imageUrlsJpg.forEach(function (url) {
// var match = url.match(imageRegex);
// if (match) {
// var fullUrl = "http://sns-webpic-qc.xhscdn.com/" + match[1] + "!nd_dft_wlteh_jpg_3";
// images.push(fullUrl);
// }
// });
// }
// // 提取标题和描述(同样使用正则表达式)
var titleMatch = responseText.match(/<title>(.*?) - 小红书<\/title>/);;
var title = titleMatch ? titleMatch[1] : "无标题";
var descriptionMatch = responseText.match(/"description" content="(.*?)">/);
var textarea = descriptionMatch ? descriptionMatch[1] : "无描述";
// 构建 JSON 对象(Auto.js 支持 JSON 对象)
var jsonObject = {
image: images,
title: title,
textarea: textarea
};
try {
const arr = [];
// 将 JSON 对象写入数组
arr.push(jsonObject);
// console.log(arr);
toast(JSON.stringify(jsonObject));
// 输出或处理 JSON 对象(在 Auto.js 中,你可以使用 log() 函数来输出信息)
// return (jsonObject);
return (JSON.stringify(arr));
} catch (error) {
/* 处理异常的代码块 */
toast('这篇文章无法获取到!请更换笔记链接!');
}
}
url = "https://www.xiaohongshu.com/explore/67092ef2000000002c02cfd5?xsec_token=AB0yB_0KJ7tobq56CwsW3Z81hWTalrz4G2d7fyQPjxyUc=&xsec_source=pc_search&source=web_explore_feed"
var textss = getUrl(url)
var json = jeixixhsurl(textss)
获取资源前请仔细阅读一下声明:
重要提示
如有解压密码: 看下载页、看下载页、看下载页。
源码工具资源类具有可复制性: 建议具有一定思考和动手能力的用户购买。
请谨慎考虑: 小白用户和缺乏思考动手能力者不建议赞助。
虚拟商品购买须知: 虚拟类商品,一经打赏赞助,不支持退款。请谅解,谢谢合作!
声明: 本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

