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


Messages In This Thread
New to Python - by Adam - Apr-11-2018, 11:46 AM
RE: New to Python - by buran - Apr-11-2018, 11:55 AM
RE: New to Python - by Adam - Apr-11-2018, 12:44 PM
RE: New to Python - by ljmetzger - Apr-11-2018, 12:58 PM
RE: New to Python - by Adam - Apr-11-2018, 01:13 PM
RE: New to Python - by buran - Apr-11-2018, 02:00 PM
RE: New to Python - by Adam - Apr-11-2018, 02:10 PM

Forum Jump:

User Panel Messages

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