import asyncio
from playwright.async_api import async_playwright
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch()
page = await browser.new_page()
await page.goto('https://qiye.58pic.com/newpic/32460413.html')
all_resources = await page.evaluate('''() => {
// 选择所有包含src或特定href属性的元素
const resources = Array.from(document.querySelectorAll(
'[src], link[rel="stylesheet"], img[src], script[src], ' +
'[href$=".css"], [href$=".js"], [href$=".json"], [href$=".m3u8"]'
));
// 提取元素的src或href属性值,过滤无效值
return resources.map(resource => resource.src || resource.href);
}''')
for resource in all_resources:
print("资源链接: ", resource)
await browser.close()
asyncio.run(main())