weixin_33735676 2016-06-10 19:45 采纳率: 0%
浏览 21

ajaxObject的更新功能

When a button is clicked on the webpage a table of data is displayed. I want to scrape that data but I can't find where it comes from in the website source code.

This is the tag for the button:

<button type="submit" onclick="divChangeStateOn('load-raw-0062294377Amazon.com'); getRaw('0062294377', 'Amazon.com', 'lr-0062294377Amazon.com',this);"style="margin-bottom: 4px; width: 120px; text-align: left;" name="load-raw"><img src='images/workstation.png'/> raw data</button>

I believe that the getRaw function is where the data comes from (I'm not positive about this) so I looked at the javascript code for the getRaw function

function getRaw(asin, store, res, caller)
{ document.getElementById(res).innerHTML = '<p align="center" valign="top"><img align="center" src="phpmy_loading.gif"></p>';
    var poststr = "raw=" + encodeURI(asin) +
                "&site=" + encodeURI(store);

   var updateResults = new ajaxObject(res, 'extra.php', caller);
   updateResults.update(poststr);
}

I have been having a hard time finding any documentation about ajaxObject and can't find any information about the update function. What is ajaxObject.update doing and is it possible for me to access the data that appears when the button is clicked?

function divChangeStateOn(divID)
{ var divElem = document.getElementById(divID);
divElem.style.display = 'block';
}

EDIT: The link to the source code view-source:http://www.ranktracer.com/account_workstation.php it might be password protected but I was just using the demo version

EDIT 2: I am basically trying to write a script that replicates the Ajax http request. This where I am at, it doesn't work and I am especially concerned about where data = uri

x = time.time()
print x
timestamp = datetime.fromtimestamp(x/1000.0)
print timestamp

uri = "raw=0062294377&site=Amazon.com&timestamp="+str(timestamp);
url = "lr-0062294377Amazon.com"

length = str(len(uri))
headers = {'X-Requested-With': 'XMLHttpRequest',
       "Content-type": "application/x-www-form-urlencoded",
       "Content-length": length,
       "Connection" : "close"}
s = Session()
r = s.post(url= url, data= uri, headers= headers)
  • 写回答

1条回答 默认 最新

  • ?yb? 2016-06-10 19:58
    关注

    The entire code for ajaxObject is present in the link you provided. Please let us know what help you are expecting here?

    function ajaxObject(layer, url, caller) {
        if (caller) {
            disableButton(caller, 'disable');
        }
        var that = this;
        var updating = false;
        this.callback = function() {}
    
    
        var LayerID = document.getElementById(layer);
    
        this.update = function(passData) {
            if (updating == true) {
                return false;
            }
            updating = true;
            var AJAX = null;
            if (window.XMLHttpRequest) {
                AJAX = new XMLHttpRequest();
            } else {
                AJAX = new ActiveXObject("Microsoft.XMLHTTP");
            }
            if (AJAX == null) {
                alert("Your browser doesn't support AJAX.");
                return false
            } else {
    
                AJAX.onreadystatechange = function() {
                    if (AJAX.readyState == 4 || AJAX.readyState == "complete") {
                        if (caller) {
                            disableButton(caller, 'enable');
                        }
                        LayerID.innerHTML = AJAX.responseText;
                        delete AJAX;
                        updating = false;
                        that.callback();
    
                    }
                }
                var timestamp = new Date();
                var uri = passData + '&timestamp=' + (timestamp * 1);
                AJAX.open("POST", url, true);
                AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                AJAX.setRequestHeader("Content-length", uri.length);
                AJAX.setRequestHeader("Connection", "close");
                AJAX.send(uri);
                return true;
            }
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大