首页 > 解决方案 > Puppeteer 不是有效的选择器

问题描述

我正在尝试使用 puppeteer 来抓取预先加载到输入框中的信息。我相信这意味着它是占位符。

我似乎无法让选择器工作。我右键单击输入框并使用chrome dev工具复制选择器,我得到#company-legal-name > span > ng-transclude > wf:textfield > div > input

但是如果我把它放到控制台中

document.querySelector('#company-legal-name > span > ng-transclude > wf:textfield > div > input')

我收到这个错误

VM637:1 Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '#company-legal-name > span > ng-transclude > wf:textfield > div > input' is not a valid selector.
at <anonymous>:1:10

我尝试了许多不同的方法,但它永远无法找到选择器。如果这有所不同,该页面似乎是有角度的。不幸的是,我无法链接该页面,因为它被锁定为非管理员。

PS:

document.getElementById('#company-legal-name')

返回null

标签: puppeteer

解决方案


wf:textfield不是有效的 CSS 选择器,因此会出现语法错误:

> document.querySelector('wf:textfield')
SyntaxError: 'wf:textfield' is not a valid selector

而没有wf:它被接受:

>document.querySelector('textfield')
null

我也对选择器有疑问ng-transclude,我猜它应该是一个(Angular?)标签名称。


推荐阅读