代码之家  ›  专栏  ›  技术社区  ›  paragbaxi

傀儡演员在Facebook设置页面返回空值

  •  0
  • paragbaxi  · 技术社区  · 5 年前

    使现代化

    我遇到的问题是在没有木偶师的情况下可以在铬上复制。我可以在浏览器中看到文本,但无法通过javascript控制台访问数据。

    起初的

    facebook隐私设置页面的选项在浏览器中可见,我可以查看它们。问题在于文档中的值。查询选择器为空。

    enter image description here

    以下是网址: https://www.facebook.com/settings

    const el = await page.$x(
              '/html/body/div[1]/div[3]/div[1]/div/div[2]/div[2]/div[2]/div/ul/li[1]/div/div/ul/li[1]/a/span[3]/div/div[2]'
            );
    const v = await page.evaluate((div) => div.textContent, el[0]);
    

    我也尝试过使用JS路径

    const v = await page.evaluate(
              () =>
                (<HTMLElement>(
                  document.querySelector(
                    '#u_fetchstream_2_4 > li:nth-child(1) > div > div > ul > li:nth-child(1) > a > span.fbSettingsListItemContent.fcg > div > div._nlm.fwb'
                  )
                )).innerText
            );
    

    始终获取以下错误:

    Error: Evaluation failed: TypeError: Cannot read property 'innerText' of null
    

    在我右键单击检查页面上的任何值之前,我已经确认该属性为null——仍然显示页面的bot检测?!

    还尝试在Chrome的控制台中使用xpath:

    $x('//*[text()="Who can see your future posts?"]')
    

    []

    0 回复  |  直到 5 年前
        1
  •  2
  •   Md. Abu Taher    5 年前

    您很有可能尝试在不同的视口维度中打开URL。这种问题发生在响应性强的网站上,这些网站上的选择器与您在浏览器中选择它们的方式大不相同。

    const browser = await puppeteer.launch({defaultViewport: null, headless: false});
    

    至于解锁,facebook和其他大公司真的不想让你去刮它们。因此,您需要结合使用良好的代理、用户代理和保密。

    您可以尝试隐形插件,它将尝试一些解锁技术。

    const puppeteer = require('puppeteer-extra')
    const StealthPlugin = require('puppeteer-extra-plugin-stealth')
    puppeteer.use(StealthPlugin())