Spaces:
Sleeping
Sleeping
File size: 1,218 Bytes
cb954a2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import requests
from bs4 import BeautifulSoup
import re
def get_historical_prices(product_url):
headers = {
'User-Agent': 'Your User Agent'
}
response = requests.get(product_url, headers=headers)
if response.status_code == 200:
soup = BeautifulSoup(response.content, 'html.parser')
price_data = {}
# Extract historical price data
price_blocks = soup.find_all('div', class_='price-history__row')
for block in price_blocks:
date = block.find('span', class_='price-history__date').text.strip()
price = block.find('span', class_='price-history__price').text.strip()
price_data[date] = price
return price_data
else:
print(f"Failed to retrieve data. Status code: {response.status_code}")
return None
# Example usage
if __name__ == '__main__':
product_url = 'https://camelcamelcamel.com/product/ASIN'
historical_prices = get_historical_prices(product_url)
if historical_prices:
print("Historical Prices:")
for date, price in historical_prices.items():
print(f"{date}: {price}")
|