Taobao for the anti-anti-anti-climbing measures detailed selenium say 2 ----- pyppeteer

Hi, Hello, everyone I go again, in the last article I share with you a universal anti-anti-selenium way pyautogui- -----> https://blog.csdn.net/qq_41927995/article/details/ 98,626,931.
If you have small partners feel this way not used to, ok! ! ! Today to analyze one I really like the library ------ pyppeteer debut! ! ! ! ! ! ! ! ! ! !
I believe many people to the library may feel very strange, I give you about a Kazakh library:

pyppeteer

1. Give everyone who introduced the source of this library bar. This library is a python-based front-end version artifact puppeteer, in fact, introduce the principle invoked Chrome DevTools open interfaces to communicate with Chrome. If you can take a look at the official documentation ---- interested Puppeteer> https://www.npmjs.com/package/puppeteer

2. When you have some understanding of how pyppeteer you will find it and selenium and PhantomJs like, ah,
in fact, really like ah. Puppeteer (pyppeteer) is Google produced a Node.js based on the development of a tool primarily used API to manipulate the Chrome browser, Chrome browser manipulated by Javascript code, so I wanted to learn this library must be sure to have a certain the foundation ah js (js I was poorly prepared, I learned a headache ah ...)

3. Presentation of the pyppeteer will have to introduce its two core:

chromium
which is Google released a browser, Chrome is the advance version of it (there are many, many questions, and very, very fun, I will give you a recent study in the browser and other organic details of this browser) We artifact pyppeteer rely on the browser is that it (do not worry you go to install it, the installation method will be introduced below)

asyncio
I believe that many of the python learned keyword should not be unfamiliar to you, it is the famous library of asynchronous these processes, we changed the whole artifact pyppeteer is asynchronous (that is, the entire process is asyncio, I do not want ah, but no way .. ... hey ....)
would like to have some understanding of this asyncio can go Liao big blog look -------> https://www.liaoxuefeng.com/wiki/1016959663602400/1017970488768640

About pyppeteer of some basic introduction on here. . . . . Now for our dinner! ! ! ! Use pyppeteer picture Taobao anti-climb, a Home login! ! !
Man of few words said, directly on the code (each line comments ah !!!!!! I'm exhausted .... the point of a concern ah)

# -*- coding: UTF-8 -*-
import asyncio
from pyppeteer import launch
import time,random

width, height = 1366, 768#设置浏览器大小
username="#####"#账号
pwd="########"#密码
async def main():
    browser = await launch(headless=False,args=[f'--window-size={width},{height}'])#类似chrom的设置
    page = await browser.newPage()#打开浏览器
    await page.setViewport({'width': width, 'height': height})#引用大小
    await page.evaluateOnNewDocument("""
    var _navigator={};
    for (name in window.navigator) {
        if (name !="webdriver"){
            _navigator[name] = window.navigator[name]
        }
    }
    Object.defineProperties(window,: 'navigator',{
        get: () =>  _navigator,
     })
    """)#这是打开访问网页前注入的js
    #类似于mitmpoxy中间人注入js


    #https://login.taobao.com/member/login.jhtml?redirectURL=https://www.taobao.com/
    await page.goto('https://login.taobao.com/member/login.jhtml?tpl_redirect_url=https%3A%2F%2Fwww.tmall.com&style=miniall&enup=true&newMini2=true&full_redirect=true&sub=true&from=tmall&allp=assets_css%3D3.0.10/login_pc.css')#访问天猫iframe的链接
    await page.evaluate('''() =>{ window.navigator.chrome = { runtime: {}, }; }''')
    await page.evaluate('''() =>{ Object.defineProperty(navigator, 'languages', { get: () => ['en-US', 'en'] }); }''')
    await page.evaluate('''() =>{ Object.defineProperty(navigator, 'plugins', { get: () => [1, 2, 3, 4, 5,6], }); }''')
    await page.evaluate('''() =>{ Object.defineProperties(navigator,{ webdriver:{ get: () => false } }) }''')       #运行程序中中可以回调的js



    await page.evaluate('''document.getElementsByClassName("J_Quick2Static")[0].click()''')#点击页面的账号密码登录
    time.sleep(1)
    # await asyncio.sleep(100)
    await page.type('.J_UserName', username, {'delay': input_time_random() - 50})#输入账号 设置输入时间
    time.sleep(1)
    await page.type('#J_StandardPwd input', pwd, {'delay': input_time_random()})#输入密码


    #如果出现滑块
    try:
        await page.hover('#nc_1_n1z')  # 不同场景的验证码模块能名字不同。
        await page.mouse.down()
        await page.mouse.move(2000, 0, {'delay': random.randint(1000, 2000)})#设置滑块速度随机
        await page.mouse.up()
        time.sleep(1)
        await page.evaluate('''document.getElementById("J_SubmitStatic").click()''')#点击登录按钮
        time.sleep(10000)
    except:
        #如果没有出现滑块
        await page.evaluate('''document.getElementById("J_SubmitStatic").click()''')#点击登录按钮
        time.sleep(1000)
def input_time_random():
    return random.randint(100, 151)#生成随机时间
asyncio.get_event_loop().run_until_complete(main())#pyppeteer调用协程

Is not at first glance have not read the code. . . . . . . It's ok. In fact, very simple (simple ass .....)
then we pyppeteer today on the introduction here
have any questions you can add me q: 1374522338
Message see also answer!

Next: Taobao for the anti-anti-anti-climbing measures detailed selenium speak 3 ----- mitmproxy

Released six original articles · won praise 32 · views 1535

Guess you like

Origin blog.csdn.net/qq_41927995/article/details/98745414