import { JSDOM } from 'jsdom'; async function getWeChatArticleLinks(publicAccountName) { // const searchUrl = `https://weixin.sogou.com/weixin?p=01030402&query=${encodeURIComponent(publicAccountName)}&type=2&ie=utf8`; // const response = await fetch(searchUrl); console.log(`https://mp.weixin.qq.com/mp/profile_ext?action=getmsg&__biz=${publicAccountName}`); const response = await fetch(`https://mp.weixin.qq.com/mp/profile_ext?action=getmsg&__biz=${publicAccountName}`, { headers: { 'Referer': `https://mp.weixin.qq.com/mp/profile_ext?action=home&__biz=${publicAccountName}` } }); const html = await response.text(); const { document } = new JSDOM(html).window; const articleLinks = []; const articleElements = document.querySelectorAll('.news-box .news-list li a'); articleElements.forEach((element) => { const link = element.href; articleLinks.push(link); }); return articleLinks; } export { getWeChatArticleLinks };