How to select elements within an iframe element in Puppeteer

前端 未结 3 1399
盖世英雄少女心
盖世英雄少女心 2020-12-31 20:23

Since ESPN does not provide an API, I am trying to use Puppeteer to scrape data about my fantasy football league. However, I am having a hard time trying to login using pupp

3条回答
  •  难免孤独
    2020-12-31 20:51

    You can get the iframe using contentFrame as you are doing now, and then call $.

    const browser = await puppeteer.launch({ headless: false });
    const page = await browser.newPage();
    
    await page.goto('http://www.espn.com/login')
    await page.waitForSelector("iframe");
    
    const elementHandle = await page.$('div#disneyid-wrapper iframe');
    const frame = await elementHandle.contentFrame();
    await frame.waitForSelector('[ng-model="vm.username"]');
    const username = await frame.$('[ng-model="vm.username"]');
    await username.type('foo');
    await browser.close()
    

提交回复
热议问题