В моем коде кукловода / javascript ниже я получаю результат, отличный от ожидаемого. Я не уверен, почему?
Я ожидаю, что значение "my json" будет возвращено внутри "price_ json" , однако это возвращает все элементы из браузера, как вы можете видеть из фактического результата.
Я не уверен, что мне не хватает базовых c javascript знаний, однако я сделал то же самое с оцените страницу, и это, кажется, работает нормально ....
Код -
const price_json = await page.on('response', async (response, i) => {
const myjson = await response.json();
console.log("inside of the page.on")
console.log(myjson)
console.log("inside (end) of the page.on")
return myjson
}, i);
console.log(price_json)
Ожидаемый результат - (мой json выглядит так)
{ unit_price: '$39.65',
carton_price: '$237.92',
stock_code: '66121' }
Фактический результат - (цена_ json после возврата ...)
_events: [Object: null prototype] { response: [AsyncFunction] },
_eventsCount: 1,
_maxListeners: undefined,
_closed: false,
_client:
CDPSession {
_events:
[Object: null prototype] {
'Fetch.requestPaused': [Function: bound _onRequestPaused],
'Fetch.authRequired': [Function: bound _onAuthRequired],
'Network.requestWillBeSent': [Function: bound _onRequestWillBeSent],
'Network.requestServedFromCache': [Function: bound _onRequestServedFromCache],
'Network.responseReceived': [Function: bound _onResponseReceived],
'Network.loadingFinished': [Function: bound _onLoadingFinished],
'Network.loadingFailed': [Function: bound _onLoadingFailed],
'Page.frameAttached': [Function],
'Page.frameNavigated': [Function],
'Page.navigatedWithinDocument': [Function],
'Page.frameDetached': [Function],
'Page.frameStoppedLoading': [Function],
'Runtime.executionContextCreated': [Function],
'Runtime.executionContextDestroyed': [Function],
'Runtime.executionContextsCleared': [Function],
'Page.lifecycleEvent': [Function],
'Target.attachedToTarget': [Function],
'Target.detachedFromTarget': [Function],
'Page.domContentEventFired': [Function],
'Page.loadEventFired': [Function],
'Runtime.consoleAPICalled': [Function],
'Runtime.bindingCalled': [Function],
'Page.javascriptDialogOpening': [Function],
'Runtime.exceptionThrown': [Function],
'Inspector.targetCrashed': [Function],
'Performance.metrics': [Function],
'Log.entryAdded': [Function],
'Page.fileChooserOpened': [Function] },
_eventsCount: 28,
_maxListeners: undefined,
_callbacks: Map {},
_connection:
Connection {
_events: [Object],
_eventsCount: 4,
_maxListeners: undefined,
_url:
'ws://127.0.0.1:58923/devtools/browser/89cbedaf-2ce2-4df8-b52b-3836987b2521',
_lastId: 87,
_callbacks: Map {},
_delay: 0,
_transport: [WebSocketTransport],
_sessions: [Map],
_closed: false },
_targetType: 'page',
_sessionId: '45363630A29A7F3799E8612DDB0C79B9' },
_target:
Target {
_targetInfo:
{ targetId: 'FB19D7C032DE5773F35827E7AECD9082',
type: 'page',
title: 'https://www.****.com.au/customers/orders',
url: 'https://www.*****.com.au/customers/orders',
attached: true,
browserContextId: '10EE70BFE005227DB58E3291908CB868' },
_browserContext:
BrowserContext {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
_connection: [Connection],
_browser: [Browser],
_id: null },
_targetId: 'FB19D7C032DE5773F35827E7AECD9082',
_sessionFactory: [Function],
_ignoreHTTPSErrors: false,
_defaultViewport: { width: 800, height: 600 },
_screenshotTaskQueue: TaskQueue { _chain: [Promise] },
_pagePromise: Promise { [Circular] },
_workerPromise: null,
_initializedCallback: [Function],
_initializedPromise: Promise { true },
_closedCallback: [Function],
_isClosedPromise: Promise { <pending> },
_isInitialized: true },
_keyboard:
Keyboard {
_client:
CDPSession {
_events: [Object],
_eventsCount: 28,
_maxListeners: undefined,
_callbacks: Map {},
_connection: [Connection],
_targetType: 'page',
_sessionId: '45363630A29A7F3799E8612DDB0C79B9' },
_modifiers: 0,
_pressedKeys: Set {} },
_mouse:
Mouse {
_client:
CDPSession {
_events: [Object],
_eventsCount: 28,
_maxListeners: undefined,
_callbacks: Map {},
_connection: [Connection],
_targetType: 'page',
_sessionId: '45363630A29A7F3799E8612DDB0C79B9' },
_keyboard:
Keyboard { _client: [CDPSession], _modifiers: 0, _pressedKeys: Set {} },
_x: 1157.59375,
_y: 422.09375,
_button: 'none' },
_timeoutSettings:
TimeoutSettings { _defaultTimeout: null, _defaultNavigationTimeout: null },
_touchscreen:
Touchscreen {
_client:
CDPSession {
_events: [Object],
_eventsCount: 28,
_maxListeners: undefined,
_callbacks: Map {},
_connection: [Connection],
_targetType: 'page',
_sessionId: '45363630A29A7F3799E8612DDB0C79B9' },
_keyboard:
Keyboard { _client: [CDPSession], _modifiers: 0, _pressedKeys: Set {} } },
_accessibility:
Accessibility {
_client:
CDPSession {
_events: [Object],
_eventsCount: 28,
_maxListeners: undefined,
_callbacks: Map {},
_connection: [Connection],
_targetType: 'page',
_sessionId: '45363630A29A7F3799E8612DDB0C79B9' } },
_frameManager:
FrameManager {
_events:
[Object: null prototype] {
[Symbol(Events.FrameManager.FrameAttached)]: [Function],
[Symbol(Events.FrameManager.FrameDetached)]: [Function],
[Symbol(Events.FrameManager.FrameNavigated)]: [Function] },
_eventsCount: 3,
_maxListeners: undefined,
_client:
CDPSession {
_events: [Object],
_eventsCount: 28,
_maxListeners: undefined,
_callbacks: Map {},
_connection: [Connection],
_targetType: 'page',
_sessionId: '45363630A29A7F3799E8612DDB0C79B9' },
_page: [Circular],
_networkManager:
NetworkManager {
_events: [Object],
_eventsCount: 4,
_maxListeners: undefined,
_client: [CDPSession],
_ignoreHTTPSErrors: false,
_frameManager: [Circular],
_requestIdToRequest: [Map],
_requestIdToRequestWillBeSentEvent: Map {},
_extraHTTPHeaders: {},
_offline: false,
_credentials: null,
_attemptedAuthentications: Set {},
_userRequestInterceptionEnabled: false,
_protocolRequestInterceptionEnabled: false,
_userCacheDisabled: false,
_requestIdToInterceptionId: Map {} },
_timeoutSettings:
TimeoutSettings { _defaultTimeout: null, _defaultNavigationTimeout: null },
_frames: Map { 'FB19D7C032DE5773F35827E7AECD9082' => [Frame] },
_contextIdToContext: Map { 5 => [ExecutionContext], 6 => [ExecutionContext] },
_isolatedWorlds: Set { '__puppeteer_utility_world__' },
_mainFrame:
Frame {
_frameManager: [Circular],
_client: [CDPSession],
_parentFrame: null,
_url: 'https://www.*****.com.au/customers/orders',
_id: 'FB19D7C032DE5773F35827E7AECD9082',
_detached: false,
_loaderId: 'D87D50CD254B4D51BD687A720F36BFCA',
_lifecycleEvents: [Set],
_mainWorld: [DOMWorld],
_secondaryWorld: [DOMWorld],
_childFrames: Set {},
_name: undefined,
_navigationURL: 'https://www.*******.com.au/customers/orders' } },
_emulationManager:
EmulationManager {
_client:
CDPSession {
_events: [Object],
_eventsCount: 28,
_maxListeners: undefined,
_callbacks: Map {},
_connection: [Connection],
_targetType: 'page',
_sessionId: '45363630A29A7F3799E8612DDB0C79B9' },
_emulatingMobile: false,
_hasTouch: false },
_tracing:
Tracing {
_client:
CDPSession {
_events: [Object],
_eventsCount: 28,
_maxListeners: undefined,
_callbacks: Map {},
_connection: [Connection],
_targetType: 'page',
_sessionId: '45363630A29A7F3799E8612DDB0C79B9' },
_recording: false,
_path: '' },
_pageBindings: Map {},
_coverage:
Coverage {
_jsCoverage:
JSCoverage {
_client: [CDPSession],
_enabled: false,
_scriptURLs: Map {},
_scriptSources: Map {},
_eventListeners: [],
_resetOnNavigation: false },
_cssCoverage:
CSSCoverage {
_client: [CDPSession],
_enabled: false,
_stylesheetURLs: Map {},
_stylesheetSources: Map {},
_eventListeners: [],
_resetOnNavigation: false } },
_javascriptEnabled: true,
_viewport: { width: 1920, height: 1080 },
_screenshotTaskQueue:
TaskQueue {
_chain:
Promise {
<Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 07 80 00 00 04 38 08 06 00 00 00 e8 d3 c1 43 00 00 00 01 73 52 47 42 00 ae ce 1c e9 00 00 20 00 ... > } },
_workers: Map {},
_fileChooserInterceptionIsDisabled: false,
_fileChooserInterceptors: Set {} }