当表格显示在页面上时,找不到“表格”

2024-04-25 05:19:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在努力刮一页纸

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'})

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

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


Tags: id元素datahtmlstocktablebootstraptheme
1条回答
网友
1楼 · 发布于 2024-04-25 05:19:21

该页面从以下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.

相关问题 更多 >