Skip to content

Instantly share code, notes, and snippets.

@cpcloud
Last active December 18, 2015 00:19
Show Gist options
  • Save cpcloud/5695835 to your computer and use it in GitHub Desktop.
Save cpcloud/5695835 to your computer and use it in GitHub Desktop.
test bs4 + lxml
from lxml.html import parse
url = 'http://www.fdic.gov/bank/individual/failed/banklist.html'
doc = parse(url)
print len(doc.xpath('.//table')) > 0
from bs4 import BeautifulSoup
from contextlib import closing
from urllib2 import urlopen
with closing(urlopen(url)) as f:
soup = BeautifulSoup(f.read(), features='lxml')
print len(soup.find_all('table')) > 0
@cpcloud
Copy link
Author

cpcloud commented Jun 3, 2013

u should see 2 Trues print out

@cpcloud
Copy link
Author

cpcloud commented Jun 3, 2013

@wesm can u tell me what output u get here, when you get a chance?

@cpcloud
Copy link
Author

cpcloud commented Jun 3, 2013

oh i used to get this error when i had 2 versions of bs4 installed, since pip is dumb and allows you to install from source and from pypi, can u confirm that you don't have both installed?

@cpcloud
Copy link
Author

cpcloud commented Jun 3, 2013

for example

pip install beautifulsoup4
pip install -e 'bzr+lp:beautifulsoup#egg=beautifulsoup4'

will install two versions. i can't repro the test failure when i do that so that might not be the issue...alas

@cpcloud
Copy link
Author

cpcloud commented Jun 3, 2013

ok i've tried this on 32 and 64 bit ubuntu 12.04, arch linux latest and all tests pass. i'm going to try with anaconda

@cpcloud
Copy link
Author

cpcloud commented Jun 3, 2013

FINALLY i can repro this when using anaconda...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment