FindAll函数的属性错误可提供漂亮的汤

时间:2019-06-21 03:18:45

标签: python-3.x beautifulsoup

我正在尝试从https://finance.yahoo.com/u/yahoo-finance/watchlists/420_stocks/收集股票行情记录,但是我一直遇到属性错误。

我还尝试了大写A和小写的findAll和find_All。

def cannabisTickersList():   
    page = urllib.request.urlopen('https://finance.yahoo.com/u/yahoo-finance/watchlists/420_stocks/').read()
    soup = bs.BeautifulSoup(page, 'lxml')
    table = soup.find_all('table', {"class" : 'cwl-symbols'})   
    cannabisTickers = []
    for table in table.find_all('tr'):
        cannabisTicker = table.find_all('td')
        cannabisTickers.append(cannabisTicker)
    with open("cannabisTickers.pickle", "wb") as f:
        pickle.dump(cannabisTickers, f)
    print([s.strip('\n') for s in cannabisTickers])
    return cannabisTickers
"ResultSet object has no attribute '%s'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?" % key

AttributeError:ResultSet对象没有属性'find_all'。您可能正在将项目列表像单个项目一样对待。当您打算致电find()时,您是否致电过find_all()?

0 个答案:

没有答案