gpt4 book ai didi

python - 表格显示在页面上时无法找到 'table'

转载 作者:行者123 更新时间:2023-12-04 15:19:42 28 4
gpt4 key购买 nike

我正在尝试抓取一个页面。

HTML 元素:

<table id="stock_ret_data" class="table table-bordered 
table-striped table-sm sortable-theme-bootstrap dataTable
no-footer" data-sortable="" role="grid"
aria-describedby="stock_ret_data_info" style="width: 1115px;">

当我尝试使用 beautifulsoup 查找表时:

soup = bs(requests.get(url).content, 'html.parser')
tbl = soup.find('table',{'id':'stock_ret_data'})

它返回空。而相同的代码适用于同一页面上的另一个表。

我不知道我可能做错了什么。

最佳答案

页面从这个 Json URL 加载数据:

import json
import requests


url = 'https://www.rupeevest.com/mf_stock_portfolio/get_stock_detail?fincode=100002'
data = requests.get(url).json()

# uncomment this to see all data:
# print(json.dumps(data, indent=4))

for d in data['stock_data']:
print(json.dumps(d, indent=4))
print('-' * 80)

打印:

{
"s_name1": "ITI Balanced Advantage Fund-Reg(G)",
"fund_manager_code": 541,
"fund_house": "ITI Mutual Fund",
"rv_sect_name": "Capital Goods",
"fund_mgr1": "George Heber Joseph",
"fincode": 100002,
"compname": "ABB India Limited",
"aum": null,
"percent_aum": null,
"month_name_1": null,
"schemecode": 44362,
"primary_fd_code": 44362,
"month_name_2": null,
"month_name_3": null,
"month_name_4": 33547
}
--------------------------------------------------------------------------------
{
"s_name1": "ITI Long Term Equity Fund-Reg(G)",
"fund_manager_code": 541,
"fund_house": "ITI Mutual Fund",
"rv_sect_name": "Capital Goods",
"fund_mgr1": "George Heber Joseph",
"fincode": 100002,
"compname": "ABB India Limited",
"aum": null,
"percent_aum": null,
"month_name_1": null,
"schemecode": 44014,
"primary_fd_code": 44014,
"month_name_2": null,
"month_name_3": 1925,
"month_name_4": 1925
}
--------------------------------------------------------------------------------

...and so on.

关于python - 表格显示在页面上时无法找到 'table',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63583094/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com