【问题标题】:'NoneType' object has no attribute 'find_all' with Beautifulsoup“NoneType”对象没有 Beautifulsoup 的“find_all”属性
【发布时间】:2022-06-17 23:29:28
【问题描述】:

我已经尝试过我找到的这段代码,但是它给了我 AttributeError 的错误消息:'NoneType' object has no attribute 'find_all' 我不熟悉 Beautifulsoup,也不知道如何解决这个问题。试图找到一个解决方案,我忽略了 tabpane 部分,但无法弄清楚。 你有什么建议吗?

import datetime
import pandas as pd # pip install pandas
import requests # pip install requests
from bs4 import BeautifulSoup # pip install beautifulsoup4

headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) 
Gecko/20100101 Firefox/87.0',
}
url = 'https://www.marketwatch.com/tools/earningscalendar'
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.content, 'html.parser')

tabpane = soup.find('div', 'tabpane')
earning_tables = tabpane.find_all('div', {'id': True})

dfs = {}
current_datetime = datetime.datetime.now().strftime('%m-%d-%y %H_%M_%S')
xlsxwriter = pd.ExcelWriter('Earning Calendar 
({0}).xlsx'.format(current_datetime), index=False)

for earning_table in earning_tables:
    if not 'Sorry, this date currently does not have any earnings 
announcements scheduled' in earning_table.text:
        earning_date = earning_table['id'].replace('page', '')
        earning_date = earning_date[:3] + '_' + earning_date[3:]
        print(earning_date)
        dfs[earning_date] = pd.read_html(str(earning_table.table))[0]
        dfs[earning_date].to_excel(xlsxwriter, sheet_name=earning_date, 
index=False)

xlsxwriter.save()
print('earning tables Excel file exported')

【问题讨论】:

  • tabpaneNone 和它后面的所有代码都是无关紧要的。

标签: python parsing beautifulsoup find-all-references


猜你喜欢
  • 1970-01-01
  • 2021-05-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-19
  • 2013-03-30
  • 2022-01-12
  • 1970-01-01
相关资源
最近更新 更多