获得指定
#pip install pyppeteer,使用 Pyppeteer(异步方案)
import asyncio
from pyppeteer import launch
async def main():browser = await launch()page = await browser.newPage()await page.goto('http://xxx/#/login')# 等待页面加载完成await page.waitForSelector('div[class="el-select"]')# 获取 div 内容div_content = await page.querySelectorEval('div[class="el-select"]', 'el => el.textContent')print(div_content)await browser.close()
asyncio.get_event_loop().run_until_complete(main())
#pip install pyppeteer,使用 Pyppeteer(异步方案)
import asyncio
from pyppeteer import launch
async def main():browser = await launch()page = await browser.newPage()await page.goto('https://www.bai.com/?tn=98010089_dg&ch=2')# 等待页面加载完成await page.waitForSelector('span[class="title-content-title"]')# 获取 div 内容div_content = await page.querySelectorEval('span[class="title-content-title"]', 'el => el.textContent')print(div_content)await browser.close()
asyncio.get_event_loop().run_until_complete(main())
获得全部
#pip install pyppeteer,使用 Pyppeteer(异步方案)
import asyncio
from pyppeteer import launch
async def main():browser = await launch()page = await browser.newPage()await page.goto('http://xxx/#/login')# 等待页面加载完成await page.waitForSelector("*")# 获取 div 内容div_content = await page.querySelectorEval('*', 'el => el.textContent')print(div_content)await browser.close()
asyncio.get_event_loop().run_until_complete(main())