Beautifulousoup找不到纳斯达克表中的班级 我正在尝试从NASDAQ收入日历中刮擦数据。 url =“ https://www.nasdaq.com/market-activity/earnings” 我想要的是实际上所有桌子,但首先,我开始尝试...

问题描述 投票:0回答:1


<div part="table-cell" role="cell" class="table-cell fixed-column-size-50px text-align-left"> <!--?lit$8289700385$--><a href="/market-activity/stocks/aapl/earnings">AAPL</a> </div>

当我通过单击2次复制类的名称并将其粘贴到Python代码时,由此产生的代码为:
class_name = """table-cell fixed-column-size-50px text-align-left""" table_cell = soup.find_all("div", {"class": class_name})
我也尝试了:

class_name = "table-cell fixed-column-size-50px text-align-left"

lastly,我在控制台中键入并执行

$0.className
,然后返回:

'table-cell\n fixed-column-size-50px\n text-align-left'

我也把它称为
class_name

,但它也没有起作用。我对HTML不熟悉,所以我搜索了类规则,但是找不到解决我的情况的解决方案。

	

数据是从REST API加载的,因此
beautifulsoup
没有看到它:

import json
import requests

import pandas as pd


url = 'https://api.nasdaq.com/api/calendar/earnings?date=2025-01-30'

headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:134.0) Gecko/20100101 Firefox/134.0'} 
data = requests.get(url, headers=headers).json()

# print(json.dumps(data, indent=4))
df = pd.DataFrame(data['data']['rows'])
print(df.head(10))

Prints:
python html python-requests
1个回答
0
投票
lastYearRptDt lastYearEPS time symbol name marketCap fiscalQuarterEnding epsForecast noOfEsts 0 2/01/2024 $2.18 time-after-hours AAPL Apple Inc. $3,601,495,987,980 Dec/2024 $2.36 11 1 1/25/2024 $2.41 time-after-hours V Visa Inc. $623,094,472,478 Dec/2024 $2.66 14 2 1/31/2024 $3.18 time-pre-market MA Mastercard Incorporated $502,383,991,486 Dec/2024 $3.68 14 3 1/31/2024 $5.67 time-pre-market TMO Thermo Fisher Scientific Inc $223,491,079,836 Dec/2024 $5.93 10 4 2/01/2024 $2.22 time-pre-market SHEL Shell PLC $197,454,356,091 Dec/2024 $1.78 3 5 2/05/2024 $5.23 time-pre-market CAT Caterpillar, Inc. $188,432,983,041 Dec/2024 $4.97 11 6 1/25/2024 $0.84 time-pre-market CMCSA Comcast Corporation $143,686,577,112 Dec/2024 $0.88 7 7 1/25/2024 $1.11 time-pre-market BX Blackstone Inc. $133,996,480,907 Dec/2024 $1.46 7 8 2/01/2024 $0.89 time-pre-market SNY Sanofi $133,992,908,715 Dec/2024 $0.71 5 9 1/30/2024 $2.47 time-pre-market UPS United Parcel Service, Inc. $115,563,305,544 Dec/2024 $2.52 9

	

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.