如何使用硒将fedex网站的表格提取到pandas数据帧中



我正试图使用硒和漂亮的汤将fedex网站((中的表提取到使用id的数据帧中,但数据帧中没有任何内容

url = 'https://www.fedex.com/en-us/shipping/fuel-surcharge.html#'
response = requests.get(url)
print(response.status_code)
soup = BeautifulSoup(response.text,"html.parser")
tables = soup.findAll('table',{"id":"international-table"})

如何将表读取到数据帧中

标签应该是<div>,而不是<table>:
import requests
import pandas as pd
from bs4 import BeautifulSoup

url = 'https://www.fedex.com/en-us/shipping/fuel-surcharge.html#'
response = requests.get(url)
soup = BeautifulSoup(response.text,"html.parser")
table = soup.find('div',{"id":"international-table"})   # <-- should be <div>, not <table>
df = pd.read_html(str(table))[0]
print(df)

打印:

0              1       2       3
0   At Least  But Less Than  Export  Import
1      $0.71          $0.75   1.75%   4.50%
2      $0.75          $0.79   2.00%   4.75%
3      $0.79          $0.83   2.25%   5.00%
4      $0.83          $0.87   2.50%   5.25%
5      $0.87          $0.91   2.75%   5.50%
6      $0.91          $0.95   3.00%   5.75%
7      $0.95          $0.99   3.25%   6.00%
8      $0.99          $1.03   3.50%   6.25%
9      $1.03          $1.07   3.75%   6.50%
10     $1.07          $1.11   4.00%   6.75%
11     $1.11          $1.15   4.25%   7.00%
12     $1.15          $1.19   4.50%   7.25%
13     $1.19          $1.23   4.75%   7.50%

最新更新