峰大爷 2022-02-23 16:33 采纳率: 83.9%
浏览 161
已结题

使用selenium运行js代码,如何获取到这段js代码的返回值啊,

function yunfeng(address,callback) {
    var yun = '';
    var url = "https://etherscan.io/tokenholdingsnew.aspx/GetAssetDetails";
    var params = { "dataTableModel": { "draw": 2, "columns": [{ "data": "TokenName", "name": "", "searchable": true, "orderable": true, "search": { "value": "", "regex": false } }, { "data": "Symbol", "name": "", "searchable": true, "orderable": false, "search": { "value": "", "regex": false } }, { "data": "ContractAddress", "name": "", "searchable": true, "orderable": false, "search": { "value": "", "regex": false } }, { "data": "Balance", "name": "", "searchable": true, "orderable": true, "search": { "value": "", "regex": false } }, { "data": "Price", "name": "", "searchable": true, "orderable": true, "search": { "value": "", "regex": false } }, { "data": "Change24H", "name": "", "searchable": true, "orderable": false, "search": { "value": "", "regex": false } }, { "data": "Value", "name": "", "searchable": true, "orderable": true, "search": { "value": "", "regex": false } }, { "data": "More", "name": "", "searchable": true, "orderable": false, "search": { "value": "", "regex": false } }], "order": [{ "column": 6, "dir": "desc" }], "start": 0, "length": 10000, "search": { "value": "", "regex": false } }, "model": { "address": address, "hideZeroAssets": false, "filteredContract": "", "showEthPrice": false } };
    var xhr = new XMLHttpRequest();
    xhr.open("POST", url, true);
    xhr.setRequestHeader("Content-Type", "application/json");
    xhr.onload = function (e) {
        if (xhr.readyState === 4) {
            if (xhr.status === 200) {
                yun = xhr.responseText;
                callback(yun)
            } else {
                console.error(xhr.statusText);
            }
        }
    };
    xhr.onerror = function (e) {
        console.error(xhr.statusText);
    };
    xhr.send(JSON.stringify(params));
    //return xhr.responseText//不能return,ajax未返回
}

var add = '0x05e793ce0c6027323ac150f6d45c2344d28b6019'
yunfeng(add, function (yun) {
    console.log(yun)
})

这段js代码,我在浏览器的控制台是可以获取到的值,但是selenium得到的就是NOne

  • 写回答

2条回答 默认 最新

查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 3月3日
  • 已采纳回答 2月23日
  • 创建了问题 2月23日

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵