• 周二. 4月 23rd, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

pyppeteer使用

admin

11月 28, 2021

 

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)

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注