I'm doing a tutorial on beautifulsoup in Python (version 2.7) with the following code:
from bs4 import BeautifulSoup
import urllib2
f = open ('C:\Python27\project\FFootball_DiamondMine\outfileESPN.txt','w')
errorFile = open ('C:\Python27\project\FFootball_DiamondMine\errorESPN.txt','w')
x = 0
while (x < 500):
soup = BeautifulSoup(urllib2.urlopen('http://games.espn.com/ffl/tools/projections?startIndex='+str(x)).read(), 'html')
tableStats = soup.find("table", {"class": "playerTableTable tableBody"})
for row in tableStats.findAll('tr')[2:]:
col =row.findAll('td')
try:
name = col[0].a.string.strip()
f.write(name+'\n')
except Exception as e:
errorFile.write(str(x) + '*********' + str(e) + '**********' + str(col) +'\n')
pass
x = x + 40
f.close()
errorFile.close()
and when I try to run it on the console I get the following error
C:\Users\Vaio\PycharmProjects\tutorial>py demo.py
Traceback (most recent call last):
File "demo.py", line 1, in <module>
from bs4 import BeautifulSoup
ImportError: No module named 'bs4'
It has been happening to me with other libraries but I do not understand what I'm doing wrong
sistema operativo : windows 7
Python: 2.7
BeautifulSoup: 3.2.1
Thank you very much for your response and attention