将jquery注入到操纵up页面 [英] inject jquery into puppeteer page
本文介绍了将jquery注入到操纵up页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将jquery注入我的伪造者页面,因为document.querySelector不会为我剪切它:
I'm trying to inject jquery into my puppeteer page because document.querySelector doesn't cut it for me:
async function inject_jquery(page){
await page.evaluate(() => {
var jq = document.createElement("script")
jq.src = "https://code.jquery.com/jquery-3.2.1.min.js"
document.querySelector("head").appendChild(jq)
})
const watchDog = page.waitForFunction('window.jQuery !== undefined');
await watchDog;
}
结果是大多数情况下超时.有人有解决方案吗?
The result is it mostly times out. Does anyone have a solution?
推荐答案
我已经使用page.addScriptTag
注入js
文件.
...
await page.addScriptTag({url: 'https://code.jquery.com/jquery-3.2.1.min.js'})
...
使用puppeteer: 0.12.0
import { launch } from 'puppeteer'
(async () => {
const browser = await launch({headless: false});
const page = await browser.newPage();
await page.goto('https://example.com', {waitUntil: 'networkidle'});
await page.addScriptTag({url: 'https://code.jquery.com/jquery-3.2.1.min.js'});
await page.close();
await browser.close();
})();
这篇关于将jquery注入到操纵up页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文