Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The issue with cars.com seems to be that they're gzipping the output twice (based on <a href="http://my.opera.com/haavard/blog/2008/10/06/browser-sniffing-gone-wrong-again-cars-com#comment19287611" rel="noreferrer">this thread</a>)</p> <p>So, we need to unzip the content... again...</p> <p>First, we need to get the content as binary, so the CFHTTP call needs to include</p> <pre><code>getasbinary="yes" </code></pre> <p>Then, we need to unzip it.</p> <p>We can use java.util.zip to do it. The gunzip is a modified version of <a href="http://cflib.org/udf/gunzipFile" rel="noreferrer">this cflib.org function</a>:</p> <pre><code>&lt;cfhttp getasbinary="yes" METHOD="get" throwonerror="yes" CHARSET="ISO-8859-1" URL="http://www.cars.com/for-sale/searchresults.action?sf1Dir=DESC&amp;prMn=1&amp;crSrtFlds=stkTypId-feedSegId-pseudoPrice&amp;rd=100000&amp;zc=44203&amp;PMmt=0-0-0&amp;stkTypId=28881&amp;sf2Dir=ASC&amp;sf1Nm=price&amp;sf2Nm=miles&amp;feedSegId=28705&amp;searchSource=UTILITY&amp;pgId=2102&amp;rpp=10" &gt; &lt;cfhttpparam type="Header" name="Accept" value="application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"&gt; &lt;cfhttpparam type="Header" name="User-Agent" value="Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.41"&gt; &lt;cfhttpparam type="Header" name="Accept-Encoding" value="deflate"&gt; &lt;cfhttpparam type="Header" name="TE" value="deflate, chunked, identity, trailers"&gt; &lt;/cfhttp&gt; &lt;cfset unzippedHTML = gunzip(cfhttp.FileContent)&gt; &lt;cfoutput&gt; #unzippedHTML# &lt;/cfoutput&gt; &lt;cfscript&gt; function gunzip(inBytes) { var gzInStream = createObject('java','java.util.zip.GZIPInputStream'); var outStream = createObject('java','java.io.ByteArrayOutputStream'); var inStream = createObject('java','java.io.ByteArrayInputStream'); var buffer = repeatString(" ",1024).getBytes(); var length = 0; var rv = ""; try { inStream.init(inBytes); gzInStream.init(inStream); outStream.init(); do { length = gzInStream.read(buffer,0,1024); if (length neq -1) outStream.write(buffer,0,length); } while (length neq -1); rv = outStream.toString(); outStream.close(); gzInStream.close(); inStream.close(); } catch (any e) { rv = ""; try { outStream.close(); } catch (any e) { } try { gzInStream.close(); } catch (any e) { try { inStream.close(); } catch (any e) {} } } return rv; } &lt;/cfscript&gt; </code></pre> <p>Be sure to double-check the var scoping of the function. I might have missed something.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload