Skip to content

Commit

Permalink
feat: 查詢 user name
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiang511 committed Aug 16, 2024
1 parent 3c2d6f3 commit d847e38
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions 測試版功能/fetch2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const fs = require('fs');
const puppeteer = require('puppeteer-core');

async function getProfilePicture(username) {
const browser = await puppeteer.launch({
executablePath: 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe', // 指定 Chrome 瀏覽器的路徑
headless:false
});
const page = await browser.newPage();
await page.goto(`https://www.threads.net/${username}`, { waitUntil: 'networkidle2' });

await page.waitForSelector('h2.x1lliihq.x1plvlek.xryxfnj', { timeout: 30000 });

const textElement = await page.$('h2.x1lliihq.x1plvlek.xryxfnj');
const text = await textElement.evaluate(element => element.textContent);

await browser.close();

return text;
}

async function processUsernames(values) {
for (const username of values) {
const profilePictureUrl = await getProfilePicture(username);

const unfollowedData = fs.readFileSync('unfollowed.json');
const unfollowedValues = JSON.parse(unfollowedData);

unfollowedValues.push({ username, profilePictureUrl });
fs.writeFileSync('unfollowed.json', JSON.stringify(unfollowedValues));
}
}

// 使用示例
const values = ['this.web', 'explainthis.io']; // 替換為實際的使用者名稱
processUsernames(values);

0 comments on commit d847e38

Please sign in to comment.