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

使用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 这个有点复杂 有没有人看看
  • ¥15 用python如何确定子元素在父元素中的位置
  • ¥15 obj文件滤除异常高程
  • ¥15 用mathematicas或者matlab计算三重积分
  • ¥15 Loop unrolling的runtime计算
  • ¥100 NVMe-oF的Target端,开启attr_offload后,测试失败。
  • ¥100 有偿照片马赛克去掉,保留原始数据
  • ¥15 c# winform http报错,如何解决?
  • ¥15 统计软件及应用-r软件
  • ¥15 爬虫返回的js数据结构如何处理