Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup
- import matplotlib.pyplot as plt
- import datetime
- # URL of the data
- url = 'https://www.gmcmap.com/historyData.asp?Param_ID=64829055160'
- # Send GET request to retrieve the data
- response = requests.get(url)
- response.raise_for_status()
- # Parse the HTML response
- soup = BeautifulSoup(response.text, 'html.parser')
- # Debug: print the HTML to inspect the structure
- #print(soup.prettify())
- # Try to find the right table
- # Adjust this selector based on the actual structure of the HTML
- table = soup.find('table', {'class': 'table table-hover'})
- # Check if table is found
- if table is None:
- print("Table not found")
- exit(1)
- # Lists to store the dates and CPM values
- dates = []
- cpm_values = []
- # Iterate through the rows of the table
- for row in table.find_all('tr')[1:]: # Skipping the header row
- cols = row.find_all('td')
- if len(cols) < 2:
- continue
- date_str = cols[0].text.strip()
- cpm_str = cols[3].text.strip()
- # Convert date string to datetime object
- try:
- date = datetime.datetime.strptime(date_str, '%Y-%m-%d %H:%M:%S')
- # Convert CPM string to float
- cpm = float(cpm_str)
- dates.append(date)
- cpm_values.append(cpm)
- except ValueError:
- continue
- # Plot the data
- plt.figure(figsize=(10, 5))
- plt.plot(dates, cpm_values, marker='o', linestyle='-', color='b')
- plt.xlabel('Date')
- plt.ylabel('uSv/h')
- plt.title('uSv/h vs Date')
- plt.grid(True)
- # Save the plot as a PNG file
- plt.savefig('usvh_vs_date.png')
- print('Plot saved as cpm_vs_date.png')
Add Comment
Please, Sign In to add comment