我正在嘗試從 Vivino 抓取資料,到目前為止我設法使用 API 并使用這篇文章從 json 檔案中讀取:
uj5u.com熱心網友回復:
資料位于window.__PRELOADED_STATE__.winePageInformation物件下的javascript中,如下所示:
<script>
window.__PRELOADED_STATE__ = ....
window.__PRELOADED_STATE__.winePageInformation = { very long JSON here }
</script>
您可以使用正則運算式來提取它,結果似乎是有效的 JSON:
import requests
import re
import json
url = "https://www.vivino.com/DK/en/pierre-amadieu-gigondas-romane-machotte-rouge/w/73846"
r = requests.get(url,
headers= {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0"
})
# this gets the javascript object
res = re.search(r"^.*window\.__PRELOADED_STATE__\.winePageInformation\s*=\s*([^;]*);", r.text, re.DOTALL)
data = json.loads(res.group(1))
print("recommended vintages")
print(data["recommended_vintages"])
print("all vintages")
print(data["wine"]["vintages"])
uj5u.com熱心網友回復:
伯特蘭給了你最好的答案。也許奇怪的是,您訪問的端點并未配置為允許您傳入葡萄酒 ID 并取回所有年份。可用的引數是:
country_code, country_codes, currency_code, discount_prices, food_ids,
grape_ids, grape_filter, max_rating, merchant_id, merchant_type, min_rating,
min_ratings_count, order_by, order, page, per_page, price_range_max,
price_range_min, region_ids, wine_style_ids, wine_type_ids, winery_ids,
vintage_ids, wine_years, excluding_vintage_id, wsa_year, top_list_filter
這些在 JS 檔案中有詳細說明https://www.vivino.com/packs/common-8f26f13b0ac53f391471.js。
您需要確定年份 ID 并將其傳遞給 API。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/321030.html
下一篇:在js中使用媒體查詢
