Python BeautifulSoup-无法从网页解析表

时间:2018-07-17 19:44:00

标签: python pandas parsing web-scraping beautifulsoup

我想从以下站点解析表数据: Pricing data并使用所有表值(vCPU,内存,存储,价格)创建一个数据框。但是,使用以下代码,我似乎无法在页面上找到该表。有人可以帮我弄清楚如何解析这些值吗?

使用pd.read_html时,显示错误,表明未找到表。

O(n)

1 个答案:

答案 0 :(得分:0)

如果您因动态内容而遇到麻烦,最好的方法是硒,它可以模拟浏览器体验,因此您不必担心管理cookie和动态Web内容附带的其他问题。我可以使用以下内容抓取页面:

import pandas as pd
from bs4 import BeautifulSoup
from selenium import webdriver
from time import sleep

driver = webdriver.Firefox()
driver.get('https://aws.amazon.com/ec2/pricing/on-demand/')
sleep(3)
html = driver.page_source
soup = BeautifulSoup(html,'lxml')
driver.close()
data=[]
tables = soup.find_all('table')
print(tables)