- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
Puppeteer 1.0.0-发布。 getProperty()
方法似乎有些神奇。例如,如果您的页面包含:
<a href="/foo/bar.html">link</a>
然后返回的不是相对而是绝对 URL:
const propertyHandle = await elementHandle.getProperty('href');
const href = await propertyHandle.jsonValue();
// href is 'https://localhost:8080/foo/bar.html'
另一方面,如果你要绕更多的路:
const hrefHandle = await page.evaluateHandle(element => element.getAttribute('href'), elementHandle);
const href = await hrefHandle.jsonValue();
// href is '/foo/bar.html'
据我所知,puppeteer 文档没有提到 getProperty()
的这种行为?
它变得更丑陋,例如,如果你想获得元素的 style
属性。看起来 puppeteer 的 getProperty()
实际上试图以某种方式解析样式,但解析存在错误/不完整。获取原始文本的唯一方法是通过迂回调用 evaluateHandle(...)
。
这是一个预期的功能,而仅仅是一个文档错误吗?还是完全是 puppeteer 错误?
谢谢。
最佳答案
参见 HTML - attributes vs properties HTML 属性和 DOM 属性之间的区别。
您也可以在没有 Puppeteer 的情况下轻松看出差异。例如,在此页面上:
document.getElementById('nav-questions').href
// returns "https://stackoverflow.com/questions"
document.getElementById('nav-questions').getAttribute('href')
// returns "/questions"
关于node.js - puppeteer 操纵者的 ElementHandle.getProperty() 的预期行为是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48654244/
我有以下代码获取“总线”层的元素句柄(在 32 个不同层的列表中) const [layerFound] = await page.$x("//div[@class='layer']/label[.=
使用 PuppeteerSharp,我试图获取元素的文本。 ElementHandle elementHandle = await page.XPathAsync("//html/body/div[1
在其他浏览器自动化框架中,往往有一个“查找”方法,允许用户找到与选择器匹配的给定元素的所有后代,例如: https://www.w3schools.com/jquery/jquery_traversi
我正在使用 playwright 版本 0.13.0, 我有一个 ElementHandle 的实例,但是 getAttribute 函数不可用,调用它会抛出一个错误说 getAttribute 不是
我在 Node.js 模块中使用 Puppeteer。我使用 XPath 选择器检索 HTML 元素,并且需要提取 text 属性。 目前我使用: // Get the element
请帮助我达到预期的结果。我将用文本填充页面上的每个输入字段:“123”。 let inputList = await page.$$('.form input'); inputList.map(asy
我正在使用 Puppeteer 版本 1.6.0 解析 html 表 // inside the rowMarket variable I store all the rows of a table
我有一个链接列表,想要 click根据链接的名称在其中之一上。我无法使用选择器完成此操作。 使用类似 page.$eval 的东西会很好获取该项目的 ElementHandle 以便我可以点击/单击它
我正在尝试迭代 ElementHandles 数组并将它们附加到第二个页面中,如下所示: const htmlContent: string = ` Section 1
关于 page.$(selector) 的文档说它返回一个包含 ElementHandle 的 promise 。 但是 ElementHandle 上的文档有点欠缺。 它说它“代表一个 DOM 元素
我正在尝试使用 Puppeteer 获取 ElementHandle 的类名......这可能吗?我使用了错误的方法吗?在这个 jsBin 是我代码的一部分,所以你可以理解我想要实现的目标。 Crit
我有一个 ElementHandle,而不是它的选择器,如何将它的 Parent 和 Siblings 作为 ElementHandle。 我知道给定元素的选择器,可以使用 const item =
我在做 const last = await page.$('.item:last-child') 现在我很想根据 last 获取前面的元素。即 const prev = last.$.prev()
我正在构建一个 scraper,但是我一直停留在遍历 elementHandles。 我需要获取我成功完成的行元素列表。在那之后,我需要为每一行捕获 tds text/innerHTML(不确定哪个是
我一直在阅读 Puppeteer API 文档,他们有 jsHandle 和 elementHandle(他们说这是 jsHandle 的扩展)。 好像page.evaluateHandle page
我目前正在与 Puppeteer 合作.我注意到在 Chrome 开发工具中,我可以从任何元素(复制/复制选择器)中获取选择器,我想知道是否也可以从 Puppeteer 中的 ElementHandl
在 Pupeteer 中,我想传递任意数量的 ElementHandle到数组中评估的方法: const element1=await page.$(".element") const element
使用节点 puppeteer 模块,如何继续使用此代码在此处获取 innerContent? const els = Promise.all(await page.$$(selector)).then
我可以很好地传递 native 对象(字符串、列表、数字等),但每当我尝试传递 JSHandle 或 ElementHandle 时,我都会收到此错误消息:“TypeError:将循环结构转换为 JS
Puppeteer 1.0.0-发布。 getProperty() 方法似乎有些神奇。例如,如果您的页面包含: link 然后返回的不是相对而是绝对 URL: const propertyHandle
我是一名优秀的程序员,十分优秀!