Juffo-Wup

Untitled

Jun 4th, 2024
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. import requests
  2. from bs4 import BeautifulSoup
  3. import matplotlib.pyplot as plt
  4. import datetime
  5.  
  6. # URL of the data
  7. url = 'https://www.gmcmap.com/historyData.asp?Param_ID=64829055160'
  8.  
  9. # Send GET request to retrieve the data
  10. response = requests.get(url)
  11. response.raise_for_status()
  12.  
  13. # Parse the HTML response
  14. soup = BeautifulSoup(response.text, 'html.parser')
  15.  
  16. # Debug: print the HTML to inspect the structure
  17. #print(soup.prettify())
  18.  
  19. # Try to find the right table
  20. # Adjust this selector based on the actual structure of the HTML
  21. table = soup.find('table', {'class': 'table table-hover'})
  22.  
  23. # Check if table is found
  24. if table is None:
  25. print("Table not found")
  26. exit(1)
  27.  
  28. # Lists to store the dates and CPM values
  29. dates = []
  30. cpm_values = []
  31.  
  32. # Iterate through the rows of the table
  33. for row in table.find_all('tr')[1:]: # Skipping the header row
  34. cols = row.find_all('td')
  35. if len(cols) < 2:
  36. continue
  37. date_str = cols[0].text.strip()
  38. cpm_str = cols[3].text.strip()
  39.  
  40. # Convert date string to datetime object
  41. try:
  42. date = datetime.datetime.strptime(date_str, '%Y-%m-%d %H:%M:%S')
  43. # Convert CPM string to float
  44. cpm = float(cpm_str)
  45.  
  46. dates.append(date)
  47. cpm_values.append(cpm)
  48. except ValueError:
  49. continue
  50.  
  51. # Plot the data
  52. plt.figure(figsize=(10, 5))
  53. plt.plot(dates, cpm_values, marker='o', linestyle='-', color='b')
  54. plt.xlabel('Date')
  55. plt.ylabel('uSv/h')
  56. plt.title('uSv/h vs Date')
  57. plt.grid(True)
  58.  
  59. # Save the plot as a PNG file
  60. plt.savefig('usvh_vs_date.png')
  61.  
  62. print('Plot saved as cpm_vs_date.png')
  63.  
Add Comment
Please, Sign In to add comment