import asyncio
import time
import numpy, random
import pyppeteer
async def main():
    ip = "xxxxxx"      #代理ip
    port = "xxxx"      #代理端口
    browser = await pyppeteer.launch({'headless': False,
                                      'args': [
                                          '--window-size={1300},{600}'
                                          '--disable-extensions',
                                          '--hide-scrollbars',
                                          '--disable-bundled-ppapi-flash',
                                          '--mute-audio',
                                          '--no-sandbox',
                                          '--disable-setuid-sandbox',
                                          '--disable-gpu',
                                          '--disable-infobars'
                                          f'--proxy-server={ip}:{port}'
                                      ],
                                      'dumpio': True
                                      })

    page = await browser.newPage()    #开启一个新页面



    await page.goto('url')   #你需要去的网页页面
    time.sleep(1)
    await page.setUserAgent('5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36')
    await page.evaluateOnNewDocument('() =>{ Object.defineProperties(navigator,'
                                          '{ webdriver:{ get: () => undefined } }) }')
    await page.evaluateOnNewDocument('() =>{ Object.defineProperties(navigator,'
                                          '{ appVersion:{ get: () => 5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 } }) }')

    frame = page.frames   #获得全部的iframe
    iframe = frame[1]
    await iframe.hover("#nc_1_n1z")   #iframe中的原素聚焦点
    await page.mouse.down()
    # time.sleep(1000)

    # 3 拖动
    print(random_linspace(100,800))
    start = 0
    end = 0
    for a in random_linspace(4,800):
        a = int(a)
        print(f'拖动{a}')
        end  =a
        print(end, start)
        await  page.mouse.move(end, start)
        start=end




def random_linspace(num, length):

    start, end = 0.5 * (length / num), 1.5 * (length / num)
    # 依靠三方库形成一个规范的等差数列,主要是得到规范等差 space
    origin_list = numpy.linspace(start, end, num)
    space = origin_list[2] - origin_list[1]
    # 在规范等差的基本上,设定左右波动的尺寸,(左右波动10%)
    min_random, max_random = -(space / 10), space / 10
    result = []
    # 等差数列的初值不会改变,便是大家设定的start
    value = start
    # 将等差数列加上到 list
    result.append(value)
    # 初值早已加上,循环系统的频次 减一
    for i in range(num - 1):
        # 波动的等误差 space
        random_space = space   random.uniform(min_random, max_random)
        value  = random_space
        result.append(value)
    return result



asyncio.get_event_loop().run_until_complete(main())
文章来源于网络,如有侵权请联系站长QQ61910465删除
本文版权归去快排Seo www.SEOgurublog.com 所有,如有转发请注明来出,竞价开户托管,seo优化请联系QQ▷61910465