gpt4 book ai didi

node.js - 剧作家无法拦截所有请求

转载 作者:行者123 更新时间:2023-12-01 21:30:56 25 4
gpt4 key购买 nike

const { webkit } = require('playwright');

(async () => {
const browser = await webkit.launch({ headless: false });
const context = await browser.newContext();
const page = await context.newPage();

// Log and continue all network requests
page.route('**', route => {
console.log(route.request());
route.continue();
});

await page.goto('https://www.sahibinden.com');
//await browser.close();
})();

当我在隐身窗口中打开它并使用 fiddler 进行拦截时,我能够获得这些 header :

X-Client-SrcPort: 49784
Accept-Language: en-US,en;q=0.9
X-J3PopQvX-a: eRELp_ivj7vKEvBmbMRSG-kfU55GIHd5Wc4a06qtEa8-W4hUa90nd0GhKDAoOzTOE6nbdU270qt3pEYVVmFKgVTToiLUqAr9yF684URRjFEdbaPsZXZSQYAJBYyvVsSi_K44SKCEGPl3aAksgQ35gw27vJvvBuscZzVhLbW5PQgfeiMKVbRrWpbR5xHUuVtZ2WWJm7HboV5kXXpkiMPA5vOktA-g4mGZm_zh6ag-OMFmLSfnepSm4PEc=xUFop6_-RYgRLI020e8S8uXXWsuQR95QLXnPCQHvZ3yRFRBtHAG6j0natnjXAxodDcm2Z_tiq7H36uRojXmBVE6A=BwWr0j-cXmsXEuSiKPairOZ6lOskntyNSoE0mao=ge0YrWgZnvEWQIb8FPadYSSufxYmxuGVur0v-5RBRcw=VCk6e6d2sbMDmuvr6zR-F_T_A4K-q-8LlnXywUUfpqG-GInbAyExoE5QdJoRiI8IdTX5NHY0uzddRbfuV9ItOwwY-0iYSMgQ=Aqr=XLeqozjSV7r_Enq0FPcQjNklgG6unf=I3VMURNTQb42pvqWK5RSa-FAD3bTCp4a_OAV=Zx3cIV9JTsSpKKMmFo5q4PMPbj9boGSLSqORhvP95PwMAxyEeMUNbnorRlVOlKH3h2h2sH9rf768CgsXo-GMzCWwQXfoEuKGyl2vRQeP_rddkJ3RHuawS=Z38p69xNcjXr9J_zX4YVoAdXxN56Jm=Qo5K8Xsz3ndwSuvBJYnPXfXNr9Et80GYIjcx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qGSI6QDSXAaoclOq4s6T2AkpRq7ZjyDmvHZIRbYeFd-E
X-Forwarded-For: 39.41.162.210
X-Forwarded-Proto: https
X-J3PopQvX-f: A3r8AMZyAQAABWpomSNWTAA_aOd-ML0d_DenMFOwBhK_GRxSWvW5FLJRxZ2sAScpotKucnW8wH8AAEB3AAAAAA==
X-J3PopQvX-c: ACCn_sVyAQAAdkviREb3CdA4iVdSrR4-Gc4Y3RxJWrLhnUx8XioZIjpANJcB
X-TLS-Version: 771
X-J3PopQvX-z: q

但是我无法通过执行上面的代码来获取这些 header 。我如何获得这些?

编辑:我使用了答案并且效果很好。只有一处缺失。

page.route('**', route => {
const request = route.request()
//console.log(request.url(), JSON.stringify(request.headers()));
return route.continue();
});
let pageRes = await page.goto(url);
await page.waitForTimeout(3 * 1000)
//await page.unroute("**");
return pageRes;

当我打印 PageRes.request().headers() 时,它不提供 j3pop header 。它只是提供

{
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.2 Safari/605.1.15'
}

编辑:这是我在交互式剧作家中尝试的

const { webkit } = require('playwright');

(async () => {
const browser = await webkit.launch();
const context = await browser.newContext();
const page = await context.newPage();

// Log and continue all network requests
headers = {}
page.route('**/*', route => {
const request = route.request()
console.log(request.url(), JSON.stringify(request.headers()));
headers = JSON.stringify(request.headers());
return route.continue();
});

let url = await page.goto('https://www.sahibinden.com/en/cars?sorting=date_desc');
console.log("headerw");
console.log(headers)
await page.waitForTimeout(3 * 1000)

await browser.close();
})();

header 没有给我 j3pop header

最佳答案

问题是,从浏览器的角度来看,页面完全加载后才会发出请求。因此,您必须使用类似 waitForTimeout 的东西等待 X 毫秒,或者使用 waitForSelector 如果您有一个最终会在您发出请求后出现的元素。

查看这个稍微修改过的示例,它会额外等待 3 秒,然后将您的请求和特殊 header 记录到控制台。

const { webkit } = require('playwright');

(async () => {
const browser = await webkit.launch();
const context = await browser.newContext();
const page = await context.newPage();

// Log and continue all network requests
await page.route('**', route => {
const request = route.request()
console.log(request.url(), JSON.stringify(request.headers()));
return route.continue();
});

await page.goto('https://www.sahibinden.com');
await page.waitForTimeout(3 * 1000)
await browser.close();
})();

或在这里互动:https://try.playwright.tech/?s=17v5y

关于node.js - 剧作家无法拦截所有请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62443318/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com