Note that there are some explanatory texts on larger screens.

plurals
  1. PO:Save html as text
    text
    copied!<p>I have a javascript code which just show the source code of a html page</p> <pre><code>javascript:h=document.getElementsByTagName('html')[0].innerHTML;function%20disp(h){h=h.replace(/&lt;/g,%20'\n&amp;lt;');h=h.replace(/&gt;/g,'&amp;gt;');document.getElementsByTagName('body')[0].innerHTML='&lt;pre&gt;&amp;lt;html&amp;gt;'+h.replace(/(\n|\r)+/g,'\n')+'&amp;lt;/html&amp;gt;&lt;/pre&gt;';}void(disp(h)); </code></pre> <p>I save the code as a bookmark in firefox. So after loading a web page, when I select the code from the bookmark, and it shows the source code.</p> <p>Now i try to save the html file using python.</p> <pre><code>from BeautifulSoup import BeautifulSoup from BeautifulSoup import BeautifulStoneSoup import BeautifulSoup import urllib2 from BeautifulSoup import BeautifulSoup page = urllib2.urlopen("http://www.doctorisin.net/") soup = BeautifulSoup(page) print soup.prettify() fp = open('file.txt','wb') fp.write(soup.prettify()) </code></pre> <p>But it does not have all the content that javascript code have. The saved file and the javascript shows source file is not same. Maybe python code does not get all the code(javascript/css tag code) from html page. What is the problem? Am i doing something wrong? Need help</p> <p>thank you</p> <p><strong>EDITED</strong></p> <p>As an example of my problem, <strong>http://phpjunkyard.com/tutorials/cut-paste-code.php</strong> (random site ) Go to this site, right click and select view page source(firefox) copy the source and save in a text file. Now save the page (save page as). You can see that both are not same. Saved page(save as) has something more. Python give the output like source code(view page source). It is missing some scripts, forms etc. </p>
 

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