Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
New to Python
#1
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()
Reply
#2
The reason for the error is that it is BeautifulSoup
Nex time post the entire traceback, not just the last line of it.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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'
Reply
#4
Case Sensitive. Upper case S in Soup.
To paraphrase: 'Throw out your dead' code. https://www.youtube.com/watch?v=grbSQ6O6kbs Forward to 1:00
Reply
#5
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
Reply
#6
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
Thanks! Ill be more carefull the next time:)
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020