V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
roiding
V2EX  ›  Node.js

有大哥用 nodejs 写过爬虫嘛

  •  
  •   roiding · Jun 8, 2022 · 4421 views
    This topic created in 1420 days ago, the information mentioned may be changed or developed.
    很简单的一个事,我就是想访问 opensea ,把 html 拉下来。但是试着用 needle 和 axios 请求都会被 cloudflare 打回来,各种 header 我都加过了。
    但是神奇的就是 postman 请求永远都是成功的,你说一直不行把 我用 needle 又请求成功一次,像请问下大哥们有人遇到过这个嘛,要怎么解决
    winnerczwx
        1
    winnerczwx  
       Jun 8, 2022
    ShayneWang
        2
    ShayneWang  
       Jun 8, 2022
    puppeteer
    duan602728596
        3
    duan602728596  
       Jun 8, 2022
    import fs from 'node:fs/promises';
    import got from 'got';
    import needle from 'needle';

    const res = await got('https://opensea.io/', {
    responseType: 'text'
    });

    await fs.writeFile('1.html', res.body);

    needle.get('https://opensea.io/', function(error, res) {
    if (!error && res.statusCode === 200)
    fs.writeFile('2.html', res.body);
    });

    测了下没问题,应该没有反爬。有可能是网络问题,毕竟服务器在境外。
    roiding
        4
    roiding  
    OP
       Jun 20, 2022
    @duan602728596 手动给你点个赞
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3738 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 05:02 · PVG 13:02 · LAX 22:02 · JFK 01:02
    ♥ Do have faith in what you're doing.