python - 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
解决方案
推荐阅读
- node.js - npm install module -g 给出 MaxListenersExceededWarning
- javascript - 限制滚动和调整大小事件
- javascript - 这是使用 JS 中相同元素的 eventListener 执行单击事件的正确纯代码吗?
- javascript - 我应该如何将滚轮或滚动事件从一个元素转移到另一个元素?
- sql - SQL查询以获取子计数并将其求和
- firebase - Firebase - 创建一个临时用户,直到用户注册
- python - 根据列值将大型 csv 拆分为较小的 csv 文件,最终在较小的文件中出现空白
- c# - 正则表达式仅选择具有一致标题的字符串中的最后一个单词
- javascript - 基于 React 的 Chrome 扩展 - 未经检查的 runtime.lastError:无法建立连接。接收端不存在
- c - 构建找不到 Stdio.h 但我可以...?