簡體   English   中英

Python BeautifulSoup-無法從網頁解析表

[英]Python BeautifulSoup - trouble parsing table from webpage

我想從以下站點解析表數據: 定價數據並創建具有所有表值(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) 

如果您因動態內容而遇到麻煩,最好的方法是硒,它可以模擬瀏覽器體驗,因此您不必擔心管理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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM