python爬虫,使用pyppeteer异步,爬取,获得指定标签内容
获得指定
#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())