Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Here is my phind.com support test #38

Open
sonygod opened this issue May 20, 2023 · 1 comment
Open

Here is my phind.com support test #38

sonygod opened this issue May 20, 2023 · 1 comment

Comments

@sonygod
Copy link

sonygod commented May 20, 2023

hello,here is my phind.com support test,windows test pass.

import fs from 'fs';
import puppeteer from 'puppeteer-extra';
import stealthPlugin from 'puppeteer-extra-plugin-stealth';
import TurndownService from 'turndown';
import pLimit from 'p-limit';
puppeteer.use(stealthPlugin());

const searchPhind = async (questions, concurrencyLimit) => {
  const searchTexts = questions.map(q => q.question);

  const search = async (searchText) => {
    const browser = await puppeteer.launch({
      headless: false,
      ignoreDefaultArgs: ["--enable-automation"],
      devtools: true,
      defaultViewport: {
        width: 1440,
        height: 900
      }
    });

    const page = await browser.newPage();
    const userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.5615.138 Safari/537.36';
    await page.setUserAgent(userAgent);
    await page.goto('https://www.phind.com/', { waitUntil: 'networkidle2',timeout: 50000 });

    const textAreaSelector = 'textarea.form-control.bg-white.darkmode-light.searchbox-textarea';
    const submitButtonSelector = 'button.btn.p-2.rounded-0[type="submit"]';
    const thumbsUpSelector = 'i.fe.fe-thumbs-up.m-2';

    await page.waitForSelector(textAreaSelector, { timeout: 500000 });
    await page.waitForSelector(submitButtonSelector, { timeout: 500000 });
    await new Promise(r => setTimeout(r, 1500));

    for (const char of searchText) {
      await page.type(textAreaSelector, char);
      await new Promise(r => setTimeout(r, 100));
    }
    await new Promise(r => setTimeout(r, 500));

    await page.click(submitButtonSelector);
    await page.waitForSelector(thumbsUpSelector, { timeout: 50000 });
    await new Promise(r => setTimeout(r, 500));

    let answer = "";
    try {
      const parentDivContent = await page.evaluate(() => {
        const h6Elements = Array.from(document.querySelectorAll('h6.text-uppercase'));
        const answerElement = h6Elements.find(el => el.textContent.trim() === 'Answer');

        if (answerElement && answerElement.parentElement) {
          return answerElement.parentElement.innerHTML;
        }
        return null;
      });
      console.log('Parent Div Content:', parentDivContent);
      answer = parentDivContent;
    }
    catch (e) {
      console.log(e);
    }

    const turndownService = new TurndownService();
    const markdown = turndownService.turndown(answer);
    fs.writeFileSync("./questions/"+searchText + '_output.md', markdown);

    browser.close();
  };

  // 使用 p-limit 限制同时运行的线程数量
  const limit = pLimit(concurrencyLimit);
  //const tasks = searchTexts.map(searchText => limit(() => search(searchText)));
  const tasks = searchTexts.map(searchText => {
    return limit(async () => {
      try {
        await search(searchText);
      } catch (error) {
        console.error(`在搜索 "${searchText}" 时发生错误:`, error);
      }
    });
  });
  await Promise.all(tasks);
};

const questions = [
  { "question": "写一段简单的c++排序" },
  { "question": "如何使用JavaScript实现快速排序" },
  { "question": "Python中如何实现二叉树" },
  { "question": "使用Java实现一个简单的计算器" },
  { "question": "如何在C#中创建一个链表" },
  { "question": "JavaScript中如何实现防抖和节流" },
  { "question": "如何使用Python进行文件读写" },
  { "question": "Go语言中如何实现并发" },
  { "question": "在Ruby中实现一个简单的Web服务器" },
  { "question": "如何使用C++进行图像处理" },
  { "question": "在Node.js中如何搭建一个RESTful API" },
  { "question": "Swift中如何实现一个简单的iOS应用" },
  { "question": "如何在PHP中连接数据库" },
  { "question": "Kotlin中如何实现Android应用的基本功能" },
  { "question": "Rust中如何实现内存安全" },
  { "question": "Scala中如何实现并行计算" },
  { "question": "如何在TypeScript中创建类" },
  { "question": "Lua中如何实现表的操作" },
  { "question": "如何在Elixir中实现简单的并发" },
  { "question": "在Haskell中如何实现函数式编程" }
];
const concurrencyLimit = 1 // 最多同时1
searchPhind(questions, concurrencyLimit);
@lys623
Copy link

lys623 commented Nov 19, 2023

brother, 429. How do you avoid it?It's been a day, and it's still 429

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants