# -*- coding: utf-8 -*-
import asyncio
from pyppeteer import launch
async def main():
browser = await launch({'headless': False})
page = await browser.newPage()
await page.goto('https://app.yinxiang.com/Login.action', {"timeout": 14 * 60000})
await page.type("#username", 'test123 哒哒哒')
asyncio.get_event_loop().run_until_complete(main())
打印信息
input options {}
char step--> t
if char key_definitions t
char step--> e
if char key_definitions e
char step--> s
if char key_definitions s
char step--> t
if char key_definitions t
char step--> 1
if char key_definitions 1
char step--> 2
if char key_definitions 2
char step--> 3
if char key_definitions 3
char step--> 哒
else char --> 哒
Traceback (most recent call last):
File "F:/code_zhu/PyCode/py_work/Alibaba/tamll_spider/tamll_spider.py", line 14, in <module>
asyncio.get_event_loop().run_until_complete(main())
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\asyncio\base_events.py", line 568, in run_until_complete
return future.result()
File "F:/code_zhu/PyCode/py_work/Alibaba/tamll_spider/tamll_spider.py", line 11, in main
await page.type("#username", 'test123 哒哒哒')
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pyppeteer\page.py", line 1589, in type
return await frame.type(selector, text, options, **kwargs)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pyppeteer\frame_manager.py", line 661, in type
await handle.type(text, options)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pyppeteer\element_handle.py", line 217, in type
await self._page.keyboard.type(text, options)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pyppeteer\input.py", line 217, in type
await self.sendCharacter(char)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pyppeteer\input.py", line 186, in sendCharacter
await self._client.send('Input.insertText', {'text': char})
pyppeteer.errors.NetworkError: Protocol error (Input.insertText): 'Input.insertText' wasn't found
Process finished with exit code 1
根据报错信息找到 input.py 文件
async def type(self, text: str, options: Dict = None, **kwargs: Any
) -> None:
options = merge_dict(options, kwargs)
print("input options", options) # 做的参数打印信息
delay = options.get('delay', 0)
for char in text:
print("char step-->", char)
if char in keyDefinitions:
print("if char key_definitions", char) # 做的参数打印信息
await self.press(char, {'delay': delay})
else:
print("else char -->", char) # 做的参数打印信息
await self.sendCharacter(char)
if delay:
await asyncio.sleep(delay / 1000)