思路代码
注释的代码:使用page.frames 不知道怎么注入JS获取滑块验证图,所以注释
6.选择器用于选择鼠标指针浮动在上面的元素
: 多次踩坑,如果没有这句,滑块就不能移动
@except_output(msg='斗鱼直播 - 异常')
async def test(self):
[page] = await self.browser.pages()
await page.setViewport(viewport={'width': self.width, 'height': self.height})
await asyncio.wait_for(page.goto('https://www.douyu.com/'), timeout=10)
# 1.定位小人物图标
await self.hover(page, '//*[@id="js-header"]/div/div/div[3]/div[7]/div/div/a/span')
# 2.点击注册
await self.click(page, '//*[@id="js-header"]/div/div/div[3]/div[7]/div/div/div/div/div/div[2]/a[2]')
# frame = page.frames
# register = frame[2]
# print(register)
# if register:
# await register.type('Input[placeholder="请输入手机号码"]', self.phone,
# {'delay': self.geetest.input_time_random()})
# await register.type('Input[placeholder="输入密码"', random.sample('1234567890zyxwvutsrqponmlkjihgfedcba', 7),
# {'delay': self.geetest.input_time_random()})
# await self.click(register, '//*[@id="loginbox"]/div[2]/div/form/div[4]/div/div/div/input[2]') # 点击
# await register.hover(
# 'body > div.geetest_panel.geetest_wind > div.geetest_panel_box > div.geetest_panel_next > div > div.geetest_wrap > div.geetest_slider.geetest_ready > div.geetest_slider_button')
# await self.jiyan(page, 'test', iframe=True) # 获取并保存图片
# 3.查找当前的注册面板对象
iframe_element = await page.J('#login-passport-frame')
if iframe_element: # 存在的话 -> 进入
# 4.选择面板对象内容框架
iframe = await iframe_element.contentFrame()
await iframe.type('Input[placeholder="请输入手机号码"]', self.phone,
{'delay': self.geetest.input_time_random()})
await iframe.type('Input[placeholder="输入密码"', random.sample('1234567890zyxwvutsrqponmlkjihgfedcba', 7),
{'delay': self.geetest.input_time_random()})
# 5.点击短信验证
await self.click(iframe, '//*[@id="loginbox"]/div[2]/div/form/div[4]/div/div/div/input[2]')
# 6.选择器用于选择鼠标指针浮动在上面的元素
await iframe.hover(
'body > div.geetest_panel.geetest_wind > div.geetest_panel_box > div.geetest_panel_next > div > div.geetest_wrap > div.geetest_slider.geetest_ready > div.geetest_slider_button')
# 7.注入JS获取滑块验证图片,并获取滑块移动的距离
await self.jiyan(page, iframe, 'test',
'/html/body/div[4]/div[2]/div[6]/div/div[1]/div[2]/div[2]')```