我想解析来自以下站点的表数据:Pricing data,并创建一个包含所有表值(vCPU、内存、存储、价格)的数据帧。但是,使用下面的代码,我似乎找不到页面上的表。有人能帮我找出如何解析这些值吗?
使用pd.read_html时,会出现找不到表的错误。
import pandas as pd
from bs4 import BeautifulSoup
import requests
import csv
url = "https://aws.amazon.com/ec2/pricing/on-demand/"
r = requests.get(url)
html_content = r.text
soup = BeautifulSoup(html_content, 'html.parser')
data=[]
tables = soup.find_all('table')
df = pd.read_html(url)
发布于 2018-07-18 05:12:23
如果你因为动态内容而遇到麻烦,一个很好的变通方法是selenium,它模拟了浏览器体验,所以你不必担心管理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)
https://stackoverflow.com/questions/51389107
复制相似问题