javascript - Why does PhantomJS not return the correct source? -


i did small test:

var page = require('webpage').create()   , fs   = require('fs');  page.open("http://www.google.it/search?q=web+design", function(status){      if (status === 'success')     {         page.render('google.png');         fs.write("source.html", page.content, 'w');      }      phantom.exit();  }) 

as can see search "web design" on google.it

now, looking source.html noticed differences between phantomjs generated source code , real (element inspector of chrome) html.

in source code result has code:

<li class="g">    <h3 class="r"><a href="/url?q=http://www.html.it/web-design/&amp;sa=u&amp;ei=z2lzubsabcgv7abm54bi&amp;ved=0ccwqfjab&amp;usg=afqjcngagkxls36cxszgjyhnbx7duci6da"><b>webdesign</b> - guide e approfondimenti per webdesigner - html.it</a></h3>    <div class="s">       <div class="kv" style="margin-bottom:2px"><cite>www.html.it/<b>web</b>-<b>design</b>/</cite><span class="flc"> - <a href="/url?q=http://webcache.googleusercontent.com/search%3fq%3dcache:3gwnt4npdr0j:http://www.html.it/web-design/%252bweb%2bdesign%26hl%3dit%26ct%3dclnk&amp;sa=u&amp;ei=z2lzubsabcgv7abm54bi&amp;ved=0cc0qidab&amp;usg=afqjcne_1gt5rl9wqagzpm_3f-oxz1vr9w">copia cache</a></span></div>       <span class="st">webdesign: progettazione web, user experience, architettura dell'informazione, <br>  consigli di esperti designer in guide e articoli di approfondimento in italiano.</span><br>    </div> </li> 

but real source (read via element inspect of chrome) is:

<li class="g">    <!--m-->    <div data-hveid="55" class="rc">       <span style="float:left"></span>       <h3 class="r"><a href="/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=2&amp;cad=rja&amp;ved=0cdgqfjab&amp;url=http%3a%2f%2fwww.html.it%2fweb-design%2f&amp;ei=wmtzufhdoyso7aagwihwdw&amp;usg=afqjcnfadzwwczdbce8tlyh9oqyluj-e5g&amp;bvm=bv.48705608,d.zgu" onmousedown="return rwt(this,'','','','2','afqjcnfadzwwczdbce8tlyh9oqyluj-e5g','','0cdgqfjab','','',event)"><em>webdesign</em> - guide e approfondimenti per webdesigner - html.it</a></h3>       <div class="s">          <div>             <div class="f kv" style="white-space:nowrap">                <cite>www.html.it/<b>web</b>-<b>design</b>/</cite>‎                <div class="action-menu ab_ctl">                   <a href="#" data-ved="0cdkq7b0waq" class="clickable-dropdown-arrow ab_button" id="am-b1" aria-label="dettagli risultato" jsaction="ab.tdd; keydown:ab.hbke; keypress:ab.mskpe" role="button" aria-haspopup="true" aria-expanded="false"><span class="mn-dwn-arw"></span></a>                   <div data-ved="0cdoqqr8waq" class="action-menu-panel ab_dropdown" jsaction="keydown:ab.hdke; mouseover:ab.hdhne; mouseout:ab.hdhue" role="menu" tabindex="-1">                      <ul>                         <li class="action-menu-item ab_dropdownitem" role="menuitem"><a href="http://webcache.googleusercontent.com/search?q=cache:3gwnt4npdr0j:www.html.it/web-design/+&amp;cd=2&amp;hl=it&amp;ct=clnk&amp;gl=it&amp;client=ubuntu" onmousedown="return rwt(this,'','','','2','afqjcneaothlal83hbobw4ue8q_opkiprw','','0cdsqidab','','',event)" class="fl">copia&nbsp;cache</a></li>                      </ul>                   </div>                </div>             </div>             <div class="f slp"></div>             <span class="st"><em>webdesign</em>: progettazione web, user experience, architettura dell'informazione, consigli di esperti designer in guide e articoli di approfondimento in italiano.</span>          </div>       </div>    </div>    <!--n--> </li> 

as can see last code more complete.

so question is:

why results have different code?

i read phantomjs executes js inside page browser does, why differences?

thank you!

because phantomjs has different user agent. if change user agent google chrome, you'll receive same result in google chrome.

you can change user agent via page.settings.useragent property.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -