JS/Html 的初学者,我试图通过 Pyppeteer0.2.5 (Python3.6.9/Chromium 87.0.4280.66) 单击无序列表中的链接。链接的html代码为:
<li class="ml2 sel"><a class="click sel clicked" href="javascript:void(0);" url="qosSettings.htm"><span class="text T">Settings</span></a></li>
我的 pyppeteer 代码是:
await page.click('[class="click sel clicked"]')
但我收到一个错误:
Traceback (most recent call last):
File "test.py", line 77, in <module>
asyncio.get_event_loop().run_until_complete(main())
File "/usr/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete
return future.result()
File "test.py", line 55, in main
await go_to_qos_settings(page)
File "test.py", line 26, in go_to_qos_settings
await page.click(btn)
File "/home/me/.local/lib/python3.6/site-packages/pyppeteer/page.py", line 1546, in click
await frame.click(selector, options, **kwargs)
File "/home/me/.local/lib/python3.6/site-packages/pyppeteer/frame_manager.py", line 581, in click
handle = await self.J(selector)
File "/home/me/.local/lib/python3.6/site-packages/pyppeteer/frame_manager.py", line 317, in querySelector
value = await document.querySelector(selector)
File "/home/me/.local/lib/python3.6/site-packages/pyppeteer/element_handle.py", line 360, in querySelector
self, selector,
File "/home/me/.local/lib/python3.6/site-packages/pyppeteer/execution_context.py", line 113, in evaluateHandle
helper.getExceptionMessage(exceptionDetails)))
pyppeteer.errors.ElementHandleError: Evaluation failed: DOMException: Failed to execute 'querySelector' on 'Document': 'javascript:void(0);' is not a valid selector.
at __pyppeteer_evaluation_script__:1:33
知道如何单击 href 为的链接javascript:void(0);
吗?从我读过的内容来看,这有时可以用一种onclick
方法代替,但在 html 代码中没有出现这样的东西。