Вы можете использовать микроформат Json, встроенный в страницу, чтобы узнать о наличии (цена, изображения, описание ...).
Например:
import json
import requests
from bs4 import BeautifulSoup
url = "https://www.zoro.com/jonard-tools-diagonal-cutting-plier-8-l-jic-2488/i/G2736212/?recommended=true"
soup = BeautifulSoup( requests.get(url).content, 'html.parser' )
data = json.loads(soup.select_one('script[type="application/ld+json"]').contents[0])
# uncomment this to print all data:
# print(json.dumps(data, indent=4))
print('Price : ', data['offers']['price'])
print('Availability: ', data['offers']['availability'])
Печать:
Price : 17.13
Availability: http://schema.org/InStock
РЕДАКТИРОВАТЬ: вы можете наблюдать все данные о продукте, встроенные в страницу:
import json
import requests
from bs4 import BeautifulSoup
url = "https://www.zoro.com/baldwin-filters-filter-service-kit-thermo-king-bk6092/i/G1609513/"
# url = 'https://www.zoro.com/jonard-tools-diagonal-cutting-plier-8-l-jic-2488/i/G2736212/?recommended=true'
soup = BeautifulSoup( requests.get(url).content, 'html.parser' )
data = json.loads(soup.select_one('div.hidden[data-state]')['data-state'] )
# uncomment this to print all data:
# print(json.dumps(data, indent=4))
_, product_data = data['product']['productDetailsData'].popitem()
print(json.dumps(product_data, indent=4))
print()
print('isExpeditable = ', product_data['isExpeditable'])
Если для этого ключа isExpeditable
установлено значение False
, это означает Drop Доставка (думаю). Когда я тестировал его с товаром, который есть в наличии, он печатал True
.
Результат:
{
"packageQty": 1,
"isMotorCompliant": false,
"zoroNo": "G1609513",
"brand": "Baldwin Filters",
"salesStatus": "TP",
"orderChannel": "Default",
"description": "Filter Service Kit, For Vehicle Type - Filter Kits Thermo King, Includes Lube Spin-On, Fuel, Water Separator Element, Fuel Spin-On",
"restrictedStates": [],
"title": "Filter Service Kit",
"categoryPaths": [
[
{
"name": "Automotive Filters",
"slug": "automotive-filters",
"code": "7540"
},
{
"name": "Filter Service Kits",
"slug": "filter-service-kits",
"code": "10660"
}
]
],
"restrictedSaleItemCode": "",
"slug": "baldwin-filters-filter-service-kit-thermo-king-bk6092",
"energyGuideLabelFileName": "",
"variants": null,
"isForcedOutOfStock": false,
"lightingFactLabelFileName": "",
"isExpeditable": false,
"erpId": "2770121",
"californiaProp65Message": null,
"isHazmat": false,
"leadTime": 8,
"mfrNo": "BK6092",
"attributes": [
{
"name": "For Vehicle Type - Filter Kits",
"value": "Thermo King"
},
{
"name": "Item",
"value": "Filter Service Kit"
},
{
"name": "For Use With",
"value": "Thermo King"
},
{
"name": "Includes",
"value": "Lube Spin-On, Fuel, Water Separator Element, Fuel Spin-On"
},
{
"name": "Country of Origin (subject to change)",
"value": "United States"
}
],
"originalPrice": null,
"isCircleECompliant": false,
"lowLeadComplianceLevel": "",
"priceUnit": "EA",
"isDropShipDirect": false,
"minRetailQty": 1,
"price": 118.29,
"media": [
{
"name": "Z1qr7ymcpEx_.JPG",
"type": "image/jpeg"
}
]
}
isExpeditable = False