Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用BeautifulSoup从UPS网站提取表格_Python_Html_Pandas_Web Scraping_Beautifulsoup - Fatal编程技术网

Python 使用BeautifulSoup从UPS网站提取表格

Python 使用BeautifulSoup从UPS网站提取表格,python,html,pandas,web-scraping,beautifulsoup,Python,Html,Pandas,Web Scraping,Beautifulsoup,我试图使用下面的代码按表id提取美国柴油价格附加费,但它只有在之前读取,而不是我做错了什么 url = 'https://www.ups.com/us/en/shipping/surcharges/fuel-surcharges.page' response = requests.get(url) print(response.status_code) soup = BeautifulSoup(response.content,"html.parser") tables =

我试图使用下面的代码按表id提取美国柴油价格附加费,但它只有在
之前读取,而不是
我做错了什么

url = 'https://www.ups.com/us/en/shipping/surcharges/fuel-surcharges.page'
response = requests.get(url)
print(response.status_code)
soup = BeautifulSoup(response.content,"html.parser")
tables = soup.find(id="USDiesel")
print(tables)
tables_all = []
for tr in tables.find_all('tr'):
    data = []
    for td in tr.find_all('td'):
        data.append(td.text.strip())
    tables_all.append(data)
table_df = pd.DataFrame(tables_all)
headers = table_df.iloc[0]
UPS_Gfuelsurcharge_df  = pd.DataFrame(table_df.values[1:], columns=headers)
print(UPS_Gfuelsurcharge_df)

该网站使用ajax加载表数据

import requests

res = requests.get("https://www.ups.com/assets/resources/fuel-surcharge/us.json")

print(res.json())

你能建议我如何提取我相对陌生的表吗this@adolfsingh您可以获得json格式的值。循环遍历json值。提及-