> uname -a
Darwin toms-MacBook-Pro.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64
..> python
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
$ uname -a
Linux pNrHP 3.6.11-1.fc17.i686 #1 SMP Mon Dec 17 22:52:59 UTC 2012 i686 i686 i386 GNU/Linux
$ ./newmenus.py ../index.html
<div id="mininav"><!-- open mininav -->
<a class="urm" href="auditions.html"><img src="auditions.png" title="Now Auditioning"/></a>
<a class="urm" href="tickets.html"><img alt="tickets" src="tickets.gif" title="buy tickets"/></a>
<a class="urm" href="individual.html#donors"><span class="urm">Donate</span></a>
<a class="urm" href="bcshop.html"><span class="urm">Shop</span></a>
<a class="urm" href="contact.php"><span class="urm">Contact</span></a>
</div>
mininav: <type 'NoneType'>
None
Traceback (most recent call last):
File "./newmenus.py", line 34, in <module>
bs=replacemenus(f.read())
File "./newmenus.py", line 21, in replacemenus
mininav.replace_with(newmininav)
AttributeError: 'NoneType' object has no attribute 'replace_with'
mininav: <class 'bs4.element.Tag'>
<div id="mininav"><!-- open mininav -->
<a href="auditions.html"><img src="auditions.png" title="Now Auditioning"/></a>
<a href="tickets.html"><img src="tickets.gif" title="buy tickets"/></a>
<a href="bcshop.html"><img src="shop.png"/></a>
<a href="press.html"><img src="press.png"/></a>
<a href="contact.php"><img src="contct.png"/></a>
</div>
../index.html ->test.new
print "mininav:", type( mininav )
An error (#340) occurred while communicating with the server.
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from bs4 import BeautifulSoup,SoupStrainer
>>> newnav = BeautifulSoup(open("navigation.html"),parse_only=SoupStrainer('div'))
>>> fn="../index.html"
>>>
>>> f= open(fn, 'r')
>>> bs= BeautifulSoup(''.join(f.read()), "html5lib")
>>> f.close()
>>>
>>> nav=bs.find(id='navigation')
>>> print "nav:", type( nav )
nav: <class 'bs4.element.Tag'>
>>> nav.replace_with(newnav)
<div id="navigation"><!-- open navigation -->
...snip...
</ul>
</div>
>>> nav=bs.find(id='navigation')
>>> print "nav:", type( nav )
nav: <type 'NoneType'>
this is only a problem in osx...in fedora17 it works as
expected....note the warning on SoupStrainer under linux, but not osx,
both running the same versions of html5lib:
beautifulsoup4 4.1.3 is already the active version in easy-install.pth
html5lib 0.95 is already the active version in easy-install.pth)-:
Python 2.7.3 (default, Jul 24 2012, 10:05:39)
[GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from bs4 import BeautifulSoup,
SoupStrainer
>>> newmininav = BeautifulSoup(open("mininav.html"),parse_only=SoupStrainer('div'))
/usr/lib/python2.7/site-packages/beautifulsoup4-4.1.3-py2.7.egg/bs4/builder/_html5lib.py:35: UserWarning: You provided a value for parse_only, but the html5lib tree builder doesn't support parse_only. The entire document will be parsed.
warnings.warn("You provided a value for parse_only, but the html5lib tree builder doesn't support parse_only. The entire document will be parsed.")
>>> newmininav=newmininav.div
>>> fn="../index.html"
>>>
>>> f= open(fn, 'r')
>>> bs= BeautifulSoup(''.join(f.read()), "html5lib")
>>> f.close()
>>>
... mininav=bs.find(id='mininav')
>>> mininav.replace_with(newmininav)
<div id="mininav"><!-- open mininav -->
<a href="auditions.html"><img src="auditions.png" title="Now Auditioning"/></a>
<a href="tickets.html"><img src="tickets.gif" title="buy tickets"/></a>
<a href="bcshop.html"><img src="shop.png"/></a>
<a href="press.html"><img src="press.png"/></a>
<a href="contact.php"><img src="contct.png"/></a>
</div>
>>> mininav=bs.find(id='mininav')
>>> mininav