【发布时间】:2018-02-07 00:41:44
【问题描述】:
Puppeteer 1.0.0-发布。 getProperty() 方法似乎有些神奇。例如,如果您的页面包含:
<a href="/foo/bar.html">link</a>
那么这将返回的不是 relative 而是一个 absolute 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(...)。
这是一个预期的功能,只是一个文档错误?还是它完全是一个木偶虫?
谢谢。
【问题讨论】: