我想从python中获取网页中的所有表格,但我的代码只显示了一个表格而不是全部。请帮忙。
提前致谢。
import pandas as pd
import requests
from bs4 import BeautifulSoup
from tabulate import tabulate
res = requests.get("http://www.findchips.com/search/PCB")
soup = BeautifulSoup(res.content,'lxml')
table = soup.find_all('table')[0]
df = pd.read_html(str(table))
print( tabulate(df[0], headers='keys', tablefmt='psql') )
答案 0 :(得分:0)
使用此:
tables = soup.find_all('table')
for table in tables
# do your stuff for every table
df = pd.read_html(str(table))
print( tabulate(df[0], headers='keys', tablefmt='psql') )