0

i'm trying to import the BeautifulSoup library directly in my python script, i can't install it because i'm using it in my Synology DS213+, so i'm trying to do this:

from BeautifulSoup import BeautifulSoup
import urllib, urllib2

opener = urllib2.build_opener(urllib2.HTTPHandler(debuglevel=0))
opener.addheaders = [('User-agent', 'Mozilla/5.0')]

ins = open( "str.txt", "r" )
array = []
for line in ins:
    array.append(line.strip())
ins.close()

for riga in array:
    print riga
    html = opener.open("http://www.mysite.com/?s="+riga)
    soup = BeautifulSoup(html)
    soup.find_all('a')
    for link in soup.find_all('a'):
        print link.get('href')

but i receive this error:

Traceback (most recent call last):
  File "myscript.py", line 17, in <module>
    soup.find_all('a')
TypeError: 'NoneType' object is not callable

i can't understand why, i put BeautifulSoup.py in the myscript.py directory, and i import in this way:

from BeautifulSoup import BeautifulSoup

what is wrong?

3
  • What version of BeautifulSoup are you using? Often the module name is bs4, and you import it with something like, "from bs4 import BeautifulSoup" Commented Feb 24, 2014 at 18:54
  • TypeError is not ImportError. If it is all you've got then you've already imported BeautifulSoup successfully. Whether your installation is broken is another question. Commented Feb 24, 2014 at 19:04
  • I use beautifulsoup 3 Commented Feb 24, 2014 at 19:29

2 Answers 2

1

There is no import error here. You've already imported BeautifulSoup successfully.

Change soup.find_all to soup.findAll to fix the TypeError.

.find_all() is for beautifulsoup4. You have BeautifulSoup 3 installed. There is no .find_all() method in this version.

By default soup.something will try to find <something> element in the html if there is no existing .something attribute. None means there is no <find_all> element. See "Using tag names as members" section.

Sign up to request clarification or add additional context in comments.

Comments

0
  1. Create a folder named BeautifulSoup next to your myscript.py file.

  2. Rename file BeautifulSoup.py to __init__.py and put it inside the BeautifulSoup folder.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.