gpt4 book ai didi

node.js - WebDriverJs 的 getPageSource 为我提供了一个对象而不是页面的源

转载 作者:太空宇宙 更新时间:2023-11-03 23:39:40 24 4
gpt4 key购买 nike

当我尝试显示页面的源代码时,

res.json 返回空白。 Selenium 日志显示已检索到源代码。知道如何正确接收更新的页面源吗?

如果我使用其他函数(例如获取当前网址),它会返回相同的结果。

代码:

var driver = new webdriver.Builder().usingServer('http://localhost:4444/wd/hub').withCapabilities(webdriver.Capabilities.firefox()).build();
driver.get('http://www.google.com');
var source = driver.getPageSource();
console.log(source);
res.json({ message: source });

console.log 输出:

 [{ then: [Function: then],                                                                                                                                                         
cancel: [Function: cancel],
isPending: [Function: isPending] }

Selenium 日志:

16:17:30.273 INFO - Executing: [new session: Capabilities [{browserName=firefox}]])                                                                                                 
16:17:30.286 INFO - Creating a new session for Capabilities [{browserName=firefox}]
16:17:39.751 INFO - Done: [new session: Capabilities [{browserName=firefox}]]
16:17:39.862 INFO - Executing: [get: http://www.google.com])
16:17:43.828 INFO - Done: [get: http://www.google.com]
16:17:43.863 INFO - Executing: [get page source])
16:17:44.036 INFO - Done: [get page source]
16:17:44.081 INFO - Executing: [delete session: d816aa4f-f5ad-4a59-aec0-4475cab4dff1])
16:17:44.206 INFO - Done: [delete session: d816aa4f-f5ad-4a59-aec0-4475cab4dff1]

最佳答案

promise获取来源,而不是来源本身。我希望你必须做类似的事情:

source.then(function (src) {
res.json({ message: src });
});

线索是,当您将 source 输出到控制台时,您会得到一个包含 thencancel 的对象>isPending 方法。 Promise 框架经常使用 then 方法来传递在 Promise 解决时调用的回调。

关于node.js - WebDriverJs 的 getPageSource 为我提供了一个对象而不是页面的源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26200939/

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