Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    408
    Thanks
    17
    Thanked 2 Times in 2 Posts

    pulling code from an iframe

    I tried to rework a short script to pull info from an iframe instead of the basic page it's sitting on, and I got confused. It's not working. Here's what I've got:

    Code:
    <script type="text/javascript" language="JavaScript">
        function find_div_class() {
           var divCollection = document.getElementById('iframeId');
    
           var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
    
           for (var i=0; i<divCollection.length; i++) {
                if(innerDoc[i].getAttribute("class") == "list-journal-entry-wrapper") {
                    findMeText = divCollection[i].innerHTML;
                    alert(findMeText);
    
          } 
            }
        }
        </script>
        
        Press the button to find the divs with class "iframeId".<br />
        <input type="button" onfocus="this.blur()" 
        value="iframeId" onclick="javascript:find_div_class();return false;""/>
    I tried another way too, but still nothing:

    Code:
    <script type="text/javascript" language="JavaScript">
        function find_div_class() {
           var divCollection = document.getElementById('iframeId');
    
           var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
    
    var info = document.getElementById("list-journal-entry-wrapper");
    
                    alert(list-journal-entry-wrapper);
    
          } 
            }
        }
        </script>
    Last edited by turpentyne; 08-26-2011 at 07:53 PM. Reason: tried another way...

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    ??? Your second way seems to have the idea, but you never define the variable iframe. And then you use document.getElementById( ) and that will try to get stuff from the main window, *not* the iframe!

    Plus you have one { but then 3 } ... never work! { and } must be matched up. Same as ( and ), [ and ].

    I *think* all you need is this:
    Code:
    <script type="text/javascript" language="JavaScript">
    function find_div_class() {
           var iframe = document.getElementById('iframeId');
           var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
           var info = innerDoc.getElementById("list-journal-entry-wrapper");
    
           alert(info); // or maybe info.innerHTML ??
    
    } 
    </script>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    408
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Cool! That did the trick.. Now, instead of "alert", I have to figure out how to search the pulled code block for the first instance of <span class="full-image-float-left ssNonEditable"> and pull the Image link that's within that span.

    The snippet of html it would be going to, should be something generally like this:

    <span class="full-image-float-left ssNonEditable"><span><img src="/storage/images/testentry1.jpg?__SQUARESPACE_CACHEVERSION=1314309812229" alt="" /></span></span>


    I've gotten to this point, but how do I get only the first instance of my span class?

    Code:
    <script type="text/javascript" language="JavaScript">
    function find_div_class() {
           var iframe = document.getElementById('IFrame2');
           var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
           var info = innerDoc.getElementById("contentWrapper");
           var drilldown = info.innerDoc.getElementByClass("full-image-float-left ssNonEditable");
    
           alert(drilldown);
    
    } 
    </script>
        
        Press the button to find the div.<br />
        <input type="button" onfocus="this.blur()" 
        value="findMeText" onclick="javascript:find_div_class();return false;""/>
    Any thoughts on that? I'm gonna look for solutions and try and wrap my head around how to do this, but maybe someone can save me a smidgeon of time?
    Last edited by turpentyne; 08-26-2011 at 11:53 PM.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    If you aren't doing this in MSIE 8 or below, it's trivial.
    Code:
    <script type="text/javascript" language="JavaScript">
    function find_div_class() {
           var iframe = document.getElementById('iframeId');
           var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
           var info = innerDoc.getElementById("list-journal-entry-wrapper");
    
           // get FIRST span with specific class name:
           var span = info.getElementsByClassName("full-image-float-left")[0];
           // get FIRST image inside that span:
           var image = span.getElementsByTagName("img")[0];
           // and then the image link:
           var theURL = image.src;
    } 
    </script>
    If you need it to work in MSIE, it's not hard. Just have to avoid getElementsByClassName.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    If it's not clear, getElementsByClassName and getElementsByTagName always return a *collection* of objects (even if the collection only has one element), so you use [ 0 ] to get the first element of the collection.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Oh, what the heck...version for old MSIE:
    Code:
    <script type="text/javascript" language="JavaScript">
    function find_div_class() {
           var iframe = document.getElementById('iframeId');
           var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
           var info = innerDoc.getElementById("list-journal-entry-wrapper");
    
           var theURL = null;  // assume not found
    
           var spans = info.getElementsByTagName("span");
           for ( var s = 0; s < spans.length; ++s )
           {
               // have to search through spans for the class name:
               var span = spans[s];
               if ( span.className.indexOf("full-image-float-left") >= 0 )
               {
                   // we found the right one
                   // get FIRST image inside that span:
                   var image = span.getElementsByTagName("img")[0];
                   // and then the image link:
                   theURL = image.src;
               }
            }
            if ( theURL == null ) alert("I can't find the darned thing!");
    } 
    </script>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Finally, that <span> you showed has two class names. If you really need to be sure you have only a <span> with *both* class names, then use the MSIE version and check for both:
    Code:
               var span = spans[s];
               if ( span.className.indexOf("full-image-float-left") >= 0 
                   && span.className.indexOf("ssNonEditable") >= 0 )
               {
                   ...
    There's a way to do this with the non-MSIE version, but w.t.h. This should work.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    Regular Coder
    Join Date
    Aug 2010
    Posts
    408
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Sorry for the delay! Weekend fun interrupted my work.

    I think I'm overlooking something. This script doesn't seem to be doing anything in Firefox, and in IE it gives an "error on page" notice at the bottom. I'm not getting the null alert, "I can't find the darned thing!".

    Here's the script:
    Code:
    <script type="text/javascript" language="JavaScript">
    function find_div_class() {
           var iframe = document.getElementById('IFrameID');
           var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
           var info = innerDoc.getElementById("list-journal-entry-wrapper");
    
           var theURL = null;  // assume not found
    
           var spans = info.getElementsByTagName("span");
           for ( var s = 0; s < spans.length; ++s )
           {
               // have to search through spans for the class name:
               var span = spans[s];
               if ( span.className.indexOf("full-image-float-left") >= 0 
                   && span.className.indexOf("ssNonEditable") >= 0 )
               {
                   // we found the right one
                   // get FIRST image inside that span:
                   var image = span.getElementsByTagName("img")[0];
                   // and then the image link:
                   theURL = image.src;
               }
            }
             if {( theURL == null ) alert("I can't find the darned thing!");}
             else {alert(theURL);}
    }
    
    </script>
        
        Press the button to find the div.<br />
        <input type="button" onfocus="this.blur()" 
        value="theURL" onclick="javascript:find_div_class();return false;""/>
    And, inside the iframe, here's the source of what I'm searching:
    Code:
    <div class="list-journal-entry-wrapper">
    
              
    
    
    <div class="journal-entry-wrapper post-text authored-by-frontdoorsnews ">
    <div id="item12614316" class="journal-entry">
    
      <div class="journal-entry-float-day"><span class="name">Wednesday</span></div><div class="journal-entry-float-date"><span class="month">Aug</span><span class="date">24</span><span class="year">2011</span></div>
    
      
      
      
      <div class="journal-entry-text">
      
          
          <h2 class="title">
        
            
        
            <a class="journal-entry-navigation-current" href="/cover_stories/2011/8/24/test-entry-4.html">test entry&nbsp;4</a>  
         
             
        
          </h2>
          
           <div class="journal-entry-tag journal-entry-tag-post-title"><span class="posted-on">   <img title="Date" alt="Date" class="inline-icon date-icon" src="/universal/images/transparent.png" />Wednesday, August 24, 2011</span> |  <span class="print-item"><a href="/cover_stories/2011/8/24/test-entry-4.html?printerFriendly=true"> <img title="Print Article" alt="Print Article" class="inline-icon print-icon" src="/universal/images/transparent.png" />&nbsp; &nbsp; Print </a></span> |  <span class="share-item"><a href="javascript:noop();" onclick="Squarespace.Interaction.shareLink(this,'%2Fcover_stories%2F2011%2F8%2F24%2Ftest-entry-4.html','test%20entry%204');"> <img title="Share Article" alt="Share Article" class="inline-icon share-icon" src="/universal/images/transparent.png" />    Share </a></span> |  <span class="email-item"><a href="/cover_stories/recommend/12614316"> <img title="Email Article" alt="Email Article" class="inline-icon email-icon" src="/universal/images/transparent.png" />&nbsp; &nbsp;  Email </a></span> </div> 
    
        
      
         
    
          <div class="body">
    
      
            
      
             
      
            <p><p><span class="full-image-float-left ssNonEditable"><span><img src="/storage/images/testentry1.jpg?__SQUARESPACE_CACHEVERSION=1314309812229" alt="" /></span></span>test entry 1 text test entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 text</p></p>
      
            <p class="journal-read-more-tag"><a href="/cover_stories/2011/8/24/test-entry-4.html">Click to read more ...</a></p>
      
          </div>
      
        
    
      </div>
    
          <div class="journal-entry-tag journal-entry-tag-post-body">
          <div class="journal-entry-tag-post-body-line1"><span class="posted-by">  <a href="/cover_stories/author/frontdoorsnews"> <img title="Author" alt="Author" class="inline-icon user-registered-icon" src="/universal/images/transparent.png" />Frontdoors News Network</a></span> </div>
    
          <div class="journal-entry-tag-post-body-line2"></div>
          <div class="journal-entry-tag-post-body-line3"></div>
        </div>
      
      
      <div class="clearer"></div>
    
    </div>
    </div>
    
    
    
    
    
    
    <div class="journal-entry-wrapper post-text authored-by-frontdoorsnews ">
    <div id="item12614313" class="journal-entry">
    
      <div class="journal-entry-float-day"><span class="name">Wednesday</span></div><div class="journal-entry-float-date"><span class="month">Aug</span><span class="date">24</span><span class="year">2011</span></div>
      
      
      
      <div class="journal-entry-text">
      
          
          <h2 class="title">
        
            
        
            <a class="journal-entry-navigation-current" href="/cover_stories/2011/8/24/test-entry-3.html">test entry&nbsp;3</a>  
         
             
        
          </h2>
    
          
           <div class="journal-entry-tag journal-entry-tag-post-title"><span class="posted-on">   <img title="Date" alt="Date" class="inline-icon date-icon" src="/universal/images/transparent.png" />Wednesday, August 24, 2011</span> |  <span class="print-item"><a href="/cover_stories/2011/8/24/test-entry-3.html?printerFriendly=true"> <img title="Print Article" alt="Print Article" class="inline-icon print-icon" src="/universal/images/transparent.png" />&nbsp; &nbsp; Print </a></span> |  <span class="share-item"><a href="javascript:noop();" onclick="Squarespace.Interaction.shareLink(this,'%2Fcover_stories%2F2011%2F8%2F24%2Ftest-entry-3.html','test%20entry%203');"> <img title="Share Article" alt="Share Article" class="inline-icon share-icon" src="/universal/images/transparent.png" />    Share </a></span> |  <span class="email-item"><a href="/cover_stories/recommend/12614313"> <img title="Email Article" alt="Email Article" class="inline-icon email-icon" src="/universal/images/transparent.png" />&nbsp; &nbsp;  Email </a></span> </div> 
    
        
      
         
    
          <div class="body">
    
      
            
      
             
      
            <p><p><span class="full-image-float-left ssNonEditable"><span><img src="/storage/images/testentry2.jpg?__SQUARESPACE_CACHEVERSION=1314309878916" alt="" /></span></span>test entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 texttest entry 1 text</p></p>
      
            <p class="journal-read-more-tag"><a href="/cover_stories/2011/8/24/test-entry-3.html">Click to read more ...</a></p>
      
          </div>
      
        
    
      </div>
    
          <div class="journal-entry-tag journal-entry-tag-post-body">
          <div class="journal-entry-tag-post-body-line1"><span class="posted-by">  <a href="/cover_stories/author/frontdoorsnews"> <img title="Author" alt="Author" class="inline-icon user-registered-icon" src="/universal/images/transparent.png" />Frontdoors News Network</a></span> </div>
    
          <div class="journal-entry-tag-post-body-line2"></div>
          <div class="journal-entry-tag-post-body-line3"></div>
        </div>
      
      
      <div class="clearer"></div>
    
    </div>
    </div>
    
    
    
    
    
    
    <div class="journal-entry-wrapper post-text authored-by-frontdoorsnews ">
    <div id="item12614307" class="journal-entry">
    
      <div class="journal-entry-float-day"><span class="name">Wednesday</span></div><div class="journal-entry-float-date"><span class="month">Aug</span><span class="date">24</span><span class="year">2011</span></div>
      
      
      
      <div class="journal-entry-text">
      
          
          <h2 class="title">
        
            
        
            <a class="journal-entry-navigation-current" href="/cover_stories/2011/8/24/test-entry-2.html">test entry&nbsp;2</a>  
         
             
        
          </h2>
    
          
           <div class="journal-entry-tag journal-entry-tag-post-title"><span class="posted-on">   <img title="Date" alt="Date" class="inline-icon date-icon" src="/universal/images/transparent.png" />Wednesday, August 24, 2011</span> |  <span class="print-item"><a href="/cover_stories/2011/8/24/test-entry-2.html?printerFriendly=true"> <img title="Print Article" alt="Print Article" class="inline-icon print-icon" src="/universal/images/transparent.png" />&nbsp; &nbsp; Print </a></span> |  <span class="share-item"><a href="javascript:noop();" onclick="Squarespace.Interaction.shareLink(this,'%2Fcover_stories%2F2011%2F8%2F24%2Ftest-entry-2.html','test%20entry%202');"> <img title="Share Article" alt="Share Article" class="inline-icon share-icon" src="/universal/images/transparent.png" />    Share </a></span> |  <span class="email-item"><a href="/cover_stories/recommend/12614307"> <img title="Email Article" alt="Email Article" class="inline-icon email-icon" src="/universal/images/transparent.png" />&nbsp; &nbsp;  Email </a></span> </div> 
    
        
      
         
    
          <div class="body">
    
      
            
      
             
      
            <p>test entry 1 summary</p>
      
            <p class="journal-read-more-tag"><a href="/cover_stories/2011/8/24/test-entry-2.html">Click to read more ...</a></p>
      
          </div>
      
        
    
      </div>
    
          <div class="journal-entry-tag journal-entry-tag-post-body">
          <div class="journal-entry-tag-post-body-line1"><span class="posted-by">  <a href="/cover_stories/author/frontdoorsnews"> <img title="Author" alt="Author" class="inline-icon user-registered-icon" src="/universal/images/transparent.png" />Frontdoors News Network</a></span> </div>
    
          <div class="journal-entry-tag-post-body-line2"></div>
          <div class="journal-entry-tag-post-body-line3"></div>
        </div>
      
      
      <div class="clearer"></div>
    
    </div>
    </div>
    
    
    
    
    
    
    <div class="journal-entry-wrapper post-text authored-by-frontdoorsnews ">
    <div id="item12614306" class="journal-entry">
    
      <div class="journal-entry-float-day"><span class="name">Wednesday</span></div><div class="journal-entry-float-date"><span class="month">Aug</span><span class="date">24</span><span class="year">2011</span></div>
      
      
      
      <div class="journal-entry-text">
      
          
          <h2 class="title">
        
            
        
            <a class="journal-entry-navigation-current" href="/cover_stories/2011/8/24/test-entry-1.html">test entry&nbsp;1</a>  
         
             
        
          </h2>
    
          
           <div class="journal-entry-tag journal-entry-tag-post-title"><span class="posted-on">   <img title="Date" alt="Date" class="inline-icon date-icon" src="/universal/images/transparent.png" />Wednesday, August 24, 2011</span> |  <span class="print-item"><a href="/cover_stories/2011/8/24/test-entry-1.html?printerFriendly=true"> <img title="Print Article" alt="Print Article" class="inline-icon print-icon" src="/universal/images/transparent.png" />&nbsp; &nbsp; Print </a></span> |  <span class="share-item"><a href="javascript:noop();" onclick="Squarespace.Interaction.shareLink(this,'%2Fcover_stories%2F2011%2F8%2F24%2Ftest-entry-1.html','test%20entry%201');"> <img title="Share Article" alt="Share Article" class="inline-icon share-icon" src="/universal/images/transparent.png" />    Share </a></span> |  <span class="email-item"><a href="/cover_stories/recommend/12614306"> <img title="Email Article" alt="Email Article" class="inline-icon email-icon" src="/universal/images/transparent.png" />&nbsp; &nbsp;  Email </a></span> </div> 
    
        
      
         
    
          <div class="body">
    
      
            
      
             
      
            <p>test entry 1 summary</p>
      
            <p class="journal-read-more-tag"><a href="/cover_stories/2011/8/24/test-entry-1.html">Click to read more ...</a></p>
      
          </div>
      
        
    
      </div>
    
          <div class="journal-entry-tag journal-entry-tag-post-body">
          <div class="journal-entry-tag-post-body-line1"><span class="posted-by">  <a href="/cover_stories/author/frontdoorsnews"> <img title="Author" alt="Author" class="inline-icon user-registered-icon" src="/universal/images/transparent.png" />Frontdoors News Network</a></span> </div>
    
          <div class="journal-entry-tag-post-body-line2"></div>
          <div class="journal-entry-tag-post-body-line3"></div>
        </div>
      
      
      <div class="clearer"></div>
    
    </div>
    </div>
    
    
    
    
    
        
        
      </div>
    
      
    
      
    
    
    </div></div>
    Last edited by turpentyne; 08-29-2011 at 07:02 PM. Reason: clarification

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Well, for starters, it helps to write *LEGAL* JavaScript.

    Does this really look legal to you:
    Code:
     if {( theURL == null ) alert("I can't find the darned thing!");}
             else {alert(theURL);}
    ????

    It should be
    Code:
            if ( theURL == null ) 
            {
                alert("I can't find the darned thing!");
            } else {
                alert(theURL);
            }
    You don't put the braces *OUTSIDE* the word "if".

    But then the other problems are:
    (1) You don't read your own code carefully.
    In the <iframe> code you have
    Code:
    <div class="list-journal-entry-wrapper">
    But then the JS code reads
    Code:
           var info = innerDoc.getElementById("list-journal-entry-wrapper");
    A class name is *NOT* an ID!!!

    I fixed it by changing that line to
    Code:
           var info = innerDoc.getElementsByClassName("list-journal-entry-wrapper")[0];
    but that won't work in MSIE versions below 9.

    (2) You are looking for a span with a class name of "full-image-float-left".
    But there are *TWO* such spans in your iframe code!!!

    WHICH ONE should you find????

    The code, as written, will always find the *last* one, however many there are.

    If you want to always find the first one, just add one line to the code:
    Code:
               if ( span.className.indexOf("full-image-float-left") >= 0 
                   && span.className.indexOf("ssNonEditable") >= 0 )
               {
                   // we found the right one
                   // get FIRST image inside that span:
                   var image = span.getElementsByTagName("img")[0];
                   // and then the image link:
                   theURL = image.src;
                   break; // quit when we find first one
               }
    It took all of about 90 seconds of debugging using FireBug in Firefox browser to find all this. *PLEASE* learn to use FireBug!
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    turpentyne (08-29-2011)

  • #10
    Regular Coder
    Join Date
    Aug 2010
    Posts
    408
    Thanks
    17
    Thanked 2 Times in 2 Posts
    I appologize for frustrating you. I am a beginner. Javascript coding is not my main focus... and thank you for suggesting firebug. I have never heard of it. That is why I did not use it.

  • #11
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Not frustrating! That was an easy one to fix. Frustrating is when there are 187 different things that have to be fixed to make the code work. <grin/>

    And apologies if I hadn't mentioned FireBug before. Trust me, the hour or two you will spend learning to use it will save you ten to fifty times that much in the long run!

    Regarding that code not working in MSIE: If the contents of the <iframe> are really what you showed, meaning that the bulk of the iframe contents are contained in that
    Code:
    <div class="list-journal-entry-wrapper">
        ...
    </div>
    then you would just get rid of one line of code and make it work in all browsers:
    Code:
    <script type="text/javascript">
    function find_div_class() {
           var iframe = document.getElementById('IFrameID');
           var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
           // remove the line where you get "info" value
    
           var theURL = null;  // assume not found
    
           // then search entire document:
           var spans = innerDoc.getElementsByTagName("span");
           for ( var s = 0; s < spans.length; ++s )
           {
               // have to search through spans for the class name:
               var span = spans[s];
               if ( span.className.indexOf("full-image-float-left") >= 0 
                   && span.className.indexOf("ssNonEditable") >= 0 )
               {
                   // we found the right one
                   // get FIRST image inside that span:
                   var image = span.getElementsByTagName("img")[0];
                   // and then the image link:
                   theURL = image.src;
                   break;
               }
            }
            if ( theURL == null ) 
            {
                alert("I can't find the darned thing!");
            } else {
                alert(theURL);
            }
    }
    </script>
    That should be more than adequate.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #12
    Regular Coder
    Join Date
    Aug 2010
    Posts
    408
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Thanks again for the help..

    unfortunately, a follow-up question about alternative methods.

    Everything worked fine until I pulled it into the full coding of Squarespace's system. Then it not only bogged down in speed, but it didn't really work within their system... and my window kept locking up. Works fine as it's own page, though.

    Is there a different way that I could get this info? I'm limited in that I can't use any server-side code on their servers. I read something about converting html to xml, but I'm not sure if that was rss feeds or something else.

    Any thoughts?

    (added after post: Wait! Maybe this is another 'duh' moment. I could go straight to the xml file with essentially the same code, It has the same span with two names, but i don't need to find the div it's in. I'm going to experiment with this, unless you think that wouldn't work... here's a bit of the feed, just to show the part I'm looking to get..almost exactly the same snippet I'm getting.

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!--Generated by Squarespace Site Server v5.11.5 (http://www.squarespace.com/) on Tue, 30 Aug 2011 17:15:52 GMT-->
    <rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><title>Cover stories</title>
    
    <link>http://www.link.com</link><description></description><generator>Squarespace Site Server v5.11.5 (http://www.squarespace.com/)</generator><item><title>test entry 4</title>
    <dc:creator>Frontdoors News Network</dc:creator><pubDate>Wed, 24 Aug 2011 19:55:36 +0000</pubDate><link>http://www.frontdoorsnews.com/cover_stories/2011/8/24/test-entry-4.html</link><guid isPermaLink="false">822467:11693620:12614316</guid>
    
    <description>
    
    <![CDATA[<span class="full-image-float-left ssNonEditable"><span><img src="http://www.frontdoorsnews.com/storage/images/cover2011jan.jpg?__SQUARESPACE_CACHEVERSION=1314647067762" alt="" /></span></span>test entry 1 text test entry 1 t 1 text]]>
    
    </description>
    
    ...the rest of the rss feed code. </item></channel></rss>
    Last edited by turpentyne; 08-30-2011 at 06:34 PM.

  • #13
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,438
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    If the XML feed is from the same domain, sure, read it instead. Almost surely more efficient.

    But caution: The CDATA there will be just ordinary text to the XML parser.

    So you might have to parse it as a string, not using DOM or XML methods.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •