Python Forum

Full Version: New to Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi! im getting stuck at this point, my code is;

The error message is AttributeError: module 'bs4' has no attribute 'Beautifulsoup'.

import bs4 as bs
import pickle
import requests

def save_sp500_tickers():
    resp = requests.get('https://en.wikipedia.org/wiki/List_of_S%26P_500_companies')
    soup = bs.Beautifulsoup(resp.text)
    table = soup.find('table',{'class':'wikitable sortable'})
    tickers = []
    for row in table.findALL('tr')[1:]:
        ticker = row.findALL('td')[0].text
        tickers.aappend(ticker)

    with open('sp500tickers.pickle','wb') as f:
        pickle.dump(tickers, f)

    print(save_sp500_tickers())

    return tickers
save_sp500_tickers()
The reason for the error is that it is BeautifulSoup
Nex time post the entire traceback, not just the last line of it.
Traceback (most recent call last):
File "/Users/adameneqvist/Desktop/FinanceAI/Finance.3.py", line 20, in <module>
save_sp500_tickers()
File "/Users/adameneqvist/Desktop/FinanceAI/Finance.3.py", line 7, in save_sp500_tickers
soup = bs.Beautifulsoup(resp.text)
AttributeError: module 'bs4' has no attribute 'Beautifulsoup'
Case Sensitive. Upper case S in Soup.
Now i get this message :(

Traceback (most recent call last):
File "/Users/adameneqvist/Desktop/FinanceAI/Finance.3.py", line 20, in <module>
save_sp500_tickers()
File "/Users/adameneqvist/Desktop/FinanceAI/Finance.3.py", line 10, in save_sp500_tickers
for row in table.findALL('tr')[1:]:
TypeError: 'NoneType' object is not callable
You need to pay more attention - python is case sensitive. It is .findAll, not .findALL
And before you ask about next error, it is .append, not .aappend
Thanks! Ill be more carefull the next time:)