Jeval == querySelectoreval
JJeval == querySelectorevalAll
import asyncio import pyppeteer async def main(): browser = await pyppeteer.launch(headless=False, args=['--disable-infobars', f'--window-size=1366,768']) page = await browser.newPage() await page.setViewport({'width': 1366, 'height': 768}) await page.evaluateOnNewdocument('Object.defineProperty(navigator,"webdriver",{get:()=>undefined})') await page.goto('https://baidu.com') # 批量属性值 获取所有满足条件的href List href = await page.querySelectorAlleval('#s-top-left > a', 'nodes => nodes.map(node => node.href)') print(href) # 批量文本值 获取所有满足条件的text List text = await page.querySelectorAlleval('#s-top-left > a', 'nodes => nodes.map(node => node.innerText)') print(text) # 单个值 info = await page.querySelectoreval('#s-top-left', 'node => node.innerText') print(info) await asyncio.sleep(100) asyncio.get_event_loop().run_until_complete(main())
['http://news.baidu.com/', 'https://www.hao123.com/', 'http://map.baidu.com/', 'https://live.baidu.com/', 'https://haokan.baidu.com/?sfrom=baidu-top', 'http://tieba.baidu.com/', 'http://xueshu.baidu.com/'] ['新闻', 'hao123', '地图', '直播', '视频', '贴吧', '学术'] 新闻hao123地图直播视频贴吧学术更多
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)