0

在下面的示例中,如何使用 playwright-dotnet 获取图像的 url?

<div class="v-image__image v-image__image--contain" 
style="background-image: url("https://example.com/myimage.jpg"); 
background-position: right center;"></div>

我试图用 await 选择 divpage.InnerHTMLAsync("div.v-image__image v-image__image--contain");无济于事。

先感谢您。

4

1 回答 1

0

正确的 CSS 选择器是DIV.v-image__image.v-image__image--contain

const browser = await playwright.chromium.launch({ headless: false });
let page = await browser.newPage();
await page.setContent(`
<div class="v-image__image v-image__image--contain" 
style='background-image: url("https://example.com/myimage.jpg"); 
background-position: right center;'></div>
`);

const el = await page.$("DIV.v-image__image.v-image__image--contain");
const styleProperty = await el.getProperty("style");
const style = await styleProperty.jsonValue();
console.log(style.backgroundImage);
await browser.close();
于 2021-12-31T22:37:47.347 回答