我正在嘗試決議以下網頁中的計劃 定價資訊。對于選項卡、概覽和評級,資料直接提供給抓取,但是對于計劃 定價,我無法呈現 html 并抓取表格資訊。
https://azuremarketplace.microsoft.com/en-us/marketplace/apps/esri.arcgis-m365?tab=PlansAndPrice
當我使用 BeautifulSoup 時:
tabelements = soup.find('div', {'class': 'tabContent'})
for eachel in tabelements:
print(eachel.text)
這僅給出“正在加載...”作為文本
我不太確定如何從這個可滾動的表格資訊中獲取表格內容。
uj5u.com熱心網友回復:
該表是從另一個源動態加載的。
要獲取資料,請嘗試以下操作:
import requests
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
}
url = "https://azuremarketplace.microsoft.com/view/appPricing/esri.arcgis-m365/us?ReviewsMyCommentsFilter=true"
skus = requests.get(url, headers=headers).json()["skus"]
for sku in skus:
print(f'{sku["id"]}\n{sku["title"]}')
price = sku["termPrices"][0]
print(f'{price["value"]} {sku["currencyCode"]}/ {price["unit"]}')
print("-" * 40)
輸出:
annualpurchase-arcgism365-1creator
..Individual Contributor (1 power user)
500 USD/ Year
----------------------------------------
annualpurchase-arcgism365-1creator10viewer
..Small Team (1 power user, 10 readers)
1500 USD/ Year
----------------------------------------
annualpurchase-arcgism365-5creator50viewer
.Medium Team (5 power users, 50 readers)
7500 USD/ Year
----------------------------------------
annualpurchase-arcgism365-10creator100viewer
Large Team (10 power users, 100 readers)
14500 USD/ Year
----------------------------------------
如果你想重建表,試試這個:
import requests
from tabulate import tabulate
headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
}
url = "https://azuremarketplace.microsoft.com/view/appPricing/esri.arcgis-m365/us?ReviewsMyCommentsFilter=true"
skus = requests.get(url, headers=headers).json()["skus"]
table_data = []
for sku in skus:
price = f'{sku["currencyCode"]}{sku["startingPrice"]["value"]}'
billing = "one time payment" \
if sku["startingPrice"]["billingPlan"] is None \
else sku["startingPrice"]["billingPlan"]
table_data.append(
[
sku["title"],
# sku["description"], uncomment to see the description
"HERE GOES THE DESCRIPTION",
f'{price}/{billing}',
sku["startingPrice"]["unit"],
f'${sku["termPrices"][0]["value"]}',
]
)
table = tabulate(
table_data,
headers=[
"Plan", "Description",
"Price payment options", "Billing term", "Subtotal"
],
)
print(table)
輸出:
Plan Description Price payment options Billing term Subtotal
---------------------------------------- ------------------------- ------------------------- -------------- ----------
..Individual Contributor (1 power user) HERE GOES THE DESCRIPTION USD500/one time payment Year $500
..Small Team (1 power user, 10 readers) HERE GOES THE DESCRIPTION USD1500/one time payment Year $1500
.Medium Team (5 power users, 50 readers) HERE GOES THE DESCRIPTION USD7500/one time payment Year $7500
Large Team (10 power users, 100 readers) HERE GOES THE DESCRIPTION USD14500/one time payment Year $14500
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/530077.html
上一篇:如何只在頁面上抓取一次URL?
下一篇:cloudcraper.exceptions.CloudflareChallengeError:檢測到Cloudflare版本2驗證碼挑戰
