【发布时间】:2022-01-23 09:11:04
【问题描述】:
Beautifull Soup 似乎无法从表中检索信息。
我要做的是检索带有标题的表并将其保存到 pands 中的数据框。非常感谢任何帮助。
import requests
from bs4 import BeautifulSoup
import pandas as pd
# Create an URL object
url = 'xxxx'
# Create object page
page = requests.get(url)
soup = BeautifulSoup(page.content, "html5lib")
data = soup.find_all("table", id="cve_table", attrs={"class": "table"})
print(len(data))
headers = []
for body in data:
print(body)
for item in body:
title = item.text
print(title)
headers.append(title)
print(headers)
我得到的只有这个:
<table class="table cell-border table-striped table-condensed table-hover" id="cve_table">
<tbody></tbody>
</table>
['\n ', '', '\n\n ']
【问题讨论】:
标签: python pandas web-scraping