我试图从下面的URL中抓取数据,以使用漂亮的soup & requests从“Growth Estimates”表中获取数据,但它似乎无法拾取该表。然而,当使用检查工具时,我可以看到有一个表可以从中提取数据,我看不到任何关于它被动态提取的信息,但我可能是错的。
url = https://finance.yahoo.com/quote/AAPL/analysis?p=AAPL
有人能解释这个问题并提供解决方案吗?
谢谢你!
import requests
from bs4 import BeautifulSoup
def get_growth_data(symbol):
url = "https://finance.yahoo.com/quote/{symbol}/analysis?p={symbol}"
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
# Find the table containing the growth data
table = soup.find("table", class_="W(100%) M(0) BdB Bdc($seperatorColor) Mb(25px)")
if table is None:
print("Table not found.")
return []
# Extract the growth values from the table
growth_values = []
rows = table.find_all("tr")
for row in rows:
columns = row.find_all("td")
if len(columns) >= 2:
growth_values.append(columns[1].text)
return growth_values
symbol = 'AAPL'
growth_data = get_growth_data(symbol)
print(growth_data)
1条答案
按热度按时间5kgi1eie1#
要从服务器获得正确的响应,请在请求中设置
User-Agent
HTTP标头:图纸: