其他分享
首页 > 其他分享> > pyppeteer使用

pyppeteer使用

作者:互联网

 

 

 

 

import asyncio
from pyppeteer import launch
import random
from bs4 import BeautifulSoup
 
width, height = 1366, 768

async def main():
    browser = await launch(headless=False, args=['--disable-infobars', f'--window-size={width},{height}'])
    page = await browser.newPage()
    await page.setViewport({'width': width, 'height': height})



    url='https://aj' 
    await page.goto(url)
    # 这里
    await page.evaluate(
        '''() =>{ Object.defineProperties(navigator,{ webdriver:{ get: () => false } }) }''')


    await page.waitFor('#queryType');
    await page.click('#queryType');
    await page.waitFor(200);
    await page.select('#queryType','yszbhstr');
    # await page.waitFor('ul.selectUl > li:last-child');
    # await page.click('ul.selectUl > li:last-child');

    await page.type('#queryKey', '2021003029', {'delay': random.randint(1, 2)})
    await page.waitFor(300)

    # await page.click('.subRes');
    await page.click("#submit")

    await page.waitFor('#content>tr>td');
    # e = await page.Jeval('#content>tr', '(els) => els.map(el => el.outerHTML)')
    # print(e)
    e = await page.Jeval('#content>tr', 'e => e.outerHTML')
    print(e)


    # ele = (await page.xpath('//tbody["content"]/tr/td'))
    # print(ele)

    
    elements = await page.xpath('//tbody[@id="content"]/tr/td')
    for element in elements:
        print(await (await element.getProperty('textContent')).jsonValue()) 

    btnId= await page.xpath('//span[@class="yfyj"]')
    btnOnclick=await (await btnId[0].getProperty('outerHTML')).jsonValue()
    soup = BeautifulSoup(btnOnclick, 'html.parser')
    span = soup.select('span')[0]
    onclick = span.get('onclick')
    print(onclick)  #xx



    pram = await page.Jeval('#param', 'e => e.value')
    print(pram)
    token = await page.Jeval('#token', 'e => e.value')
    print(token)

 

标签:await,waitFor,pyppeteer,tr,content,使用,print,page
来源: https://www.cnblogs.com/yansc/p/15111006.html