Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BeautifulSoup(html) not working, saying can't call module?

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.

like image 992
Blankman Avatar asked Jul 30 '10 01:07

Blankman


1 Answers

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)
like image 139
Blair Conrad Avatar answered Oct 11 '22 14:10

Blair Conrad