# -*- 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)
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.