request-html 登陆百度

import asyncio

from requests_html import HTMLSession

url  = 'https://passport.baidu.com/v2/?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F&sms=5'

session = HTMLSession( browser_args=[
        '--no-sand',
        '--disable-infobars'
        '--user-agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36'
    ],headless=False)
res = session.request(url=url,method='GET')
script = """
                () => {
                    return {
                        width: document.documentElement.clientWidth,
                        height: document.documentElement.clientHeight,
                        deviceScaleFactor: window.devicePixelRatio,
                    }
                }
               """
try:
    res.html.render(keep_page = True)
    async def main():

        await res.html.page.waitFor(1000)
        await res.html.page.click(' [id = "TANGRAM__PSP_3__footerULoginBtn"]')
        await res.html.page.type(' [id="TANGRAM__PSP_3__userName"]','maonanbei')
        await res.html.page.type(' [id="TANGRAM__PSP_3__password"]','goudouxi')
        await res.html.page.screenshot({'path': 'login.png'})

        await res.html.page.waitFor(100000000)
    asyncio.get_event_loop().run_until_complete(main())
except Exception as e:
    print(e)
finally:
    session.close()

猜你喜欢

转载自www.cnblogs.com/ruhai/p/11318499.html