Changeset 11287

Show
Ignore:
Timestamp:
05/09/08 04:22:04 (5 years ago)
Author:
stomita
Message:

lang/javascript/jsAutoPageScraper: fixed nextLink, xpath-javascript load for non-native support browsers

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/jsAutoPageScraper/trunk/js/jsAutoPageScraper.js

    r9590 r11287  
    11/** 
    2  * jsAutoPageScraper 0.2 
     2 * jsAutoPageScraper 0.3 
    33 * 
    44 * (c) mashmatrix, inc. 
     
    5252 */ 
    5353function createIframe(url, callback, scope) { 
    54   // ugly W/A to prevent cache... 
    55   if (url == window.location.href) { 
    56     url += url.indexOf('?') >= 0 ? '&' : '?'; 
    57   } 
    5854  var iframeEl = windoc.createElement('iframe'); 
    5955  iframeEl.style.width = iframeEl.style.height = 0; 
    6056  iframeEl.style.visibility = 'hidden'; 
    6157  iframeEl.style.position = 'absolute'; 
    62   iframeEl.src = url; 
     58  iframeEl.src = "about:blank"; 
     59 
     60  getBodyEl().appendChild(iframeEl); 
    6361 
    6462  addEvent(iframeEl, 'load', function() { 
     
    6765  }); 
    6866 
    69   getBodyEl().appendChild(iframeEl); 
     67  iframeEl.contentWindow.location.href = url; 
    7068 
    7169} 
     
    10098    var scriptEl = doc.createElement('script'); 
    10199    scriptEl.type = 'text/javascript'; 
    102     scriptEl.src = xpathLibUrl; 
     100    scriptEl.src = xpathLibUrl + '?useNative=false'; 
    103101    doc.documentElement.appendChild(scriptEl); 
    104102    pollXPathLibLoadStatus(); 
     
    198196     .skip(5) 
    199197     .scrape(10, callback2) 
    200      .wait(); 
     198     .force(); 
    201199 
    202200 function callback1(records) { ... } 
     
    269267 
    270268  /** 
    271    * Refresh queued commands and wait next command by keeping current cursor and resources. 
     269   * Wait next command by keeping current cursor and resources. 
    272270   * 
     271   * @param {Number} msec - msec to wait for next fetch (optional) 
    273272   * @returns Self instance 
    274273   * @type JSAutoPageScraper 
    275274   */ 
    276   wait : function() { 
    277     this.force(); 
     275  wait : function(msec) { 
     276    var _this = this; 
     277    if (msec) { 
     278      var cmd = { 
     279        method : 'wait',  
     280        args : [ msec, function() { _this.force() } ] 
     281      } 
     282      this.cmdQueue.push(cmd); 
     283    } 
    278284    return this; 
    279285  } 
     
    347353 
    348354  /** 
     355   * Wait scraping 
     356   *  
     357   * @param {Number} msec - Waiting time (in milliseconds) 
     358   * @param {Function} callback - Callbacked when timeouted. 
     359   */ 
     360  wait : function(msec, callback) { 
     361    window.setTimeout(callback, msec); 
     362  } 
     363  , 
     364 
     365  /** 
    349366   * Clear and reset fetching states. 
    350367   */ 
     
    394411    } else if (this.paragraphs.length == 0) { 
    395412      delete this.paragraphs; 
    396       this.nextUrl = queryXPathElement(this.doc, this.siteinfo.nextLink); 
     413      var nextLink = queryXPathElement(this.doc, this.siteinfo.nextLink); 
     414      this.currUrl = nextLink && nextLink.href; 
    397415      this.cleanupIframe(); 
    398       if (!this.nextUrl) { 
     416      if (!this.currUrl) { 
    399417        this.onFinish(); 
    400418      } else {