首页 > 解决方案 > Beautiful Soup 不返回表中的数据

问题描述

我想从一个登录的网站中检索财务数据集。我已经设法使用请求登录并访问 HTML

from bs4 import BeautifulSoup
import pandas as pd 
s = requests.session()
login_data = dict(email='my login', password='password')
s.post('*portal webiste with/login*', data=login_data)
r = s.get(' *website with finacial page* ')
print (r.content)
## work on r as its a direct link 
 
url = r # stock url
page = url
soup = BeautifulSoup(page.text) # returns the htm of the finance page.

上面的代码允许我登录并从正确的页面获取 html。

headers = []
# finds all the headers.
for i in table.find_all('th'):
    title = i.text.strip()
    headers.append(title)
    
    
df = pd.DataFrame(columns = headers)

print(df)

此块查找表并获取列标题。

打印为:

Columns: [Date, Type, Type, Credit, Debit, Outstanding, Case File, ]

下一部分是问题。当我尝试使用以下代码检索财务时:

for row in table.find_all('tr')[1:]:
    data = row.find_all('td')
    row_data = [td.text.strip()for td in data]
    print(row_data)

它返回这个

['"Loading Please Wait..."']

网站的 HTML 看起来像 我要抓取的网站的 html

标签: pythonhtmlbeautifulsouppython-requestsscreen-scraping

解决方案


推荐阅读