views:

65

answers:

2
import urllib2
import urllib
from BeautifulSoup import BeautifulSoup        # html
from BeautifulSoup import BeautifulStoneSoup     # xml
import BeautifulSoup                # everything
import re


f = o.open( 'http://www.google.com', p)
html = f.read()
f.close()


soup = BeautifulSoup(html)

Getting an error saying the line with soup = BeautifulSoup(html) says 'module' object is not callable.

+5  A: 

Your import BeautifulSoup makes BeautifulSoup refer to the module, not the class as it did after from BeautifulSoup import BeautifulSoup. If you're going to import the whole module, you might want to omit the from ... line or perhaps rename the class afterward:

from BeautifulSoup import BeautifulSoup 
Soup = BeautifulSoup
...
import BeautifulSoup
....
soup = Soup(html)
Blair Conrad
that fixed it thanks.
Blankman
+3  A: 

@Blair's answer has the right slant but I'd perform some things slightly differently, i.e.:

import BeautifulSoup
Soup = BeautifulSoup.BeautifulSoup

(recommended), or

import BeautifulSoup
from BeautifulSoup import BeautifulSoup as Soup

(not bad either).

Alex Martelli
Yes. Much better.
Blair Conrad