0

I attempted to look this up but I can't seem to find what I need. I have this URL i'm trying to extract data from. I want to get only the uptime percentage for the last 30 days (bottom left). My first idea was to convert the contents of the page to a string then find the last occurrence of "%" and go back 5 characters then display the next 5 characters. But I don't even know how I'd go about doing that. My experiments have not gone well. But I feel there's a better way to do it. I was hoping it would have an ID I could use to locate it but it doesn't. So do you have any ides how I can get that percentage so I can echo it on my page? Preferably using PHP? Thanks for any help, I'm lost with this one. And sorry for the very broad question, I just don't know where else to turn.

Syllith
  • 189
  • 10
  • To help you out a little further, using `DOMXPath`, a query like `//section[@id="overall-uptime"]/ul/li[3]/strong/@text` should get you what you want – Phil Oct 01 '18 at 01:39
  • Thanks, I'm trying it out now. This is new to me so I'm struggling a bit. Trying to figure out how to use DOM right now. I've download phpquery.php and stuck it on my page. In the example http://php.net/manual/en/book.dom.php, under $html, should I have it = file_get_contents("https://stats.uptimerobot.com/2Wo6QSP4Y"); ? – Syllith Oct 01 '18 at 01:44
  • I would highly recommend sticking to the built-in PHP DOM methods. And yes, that's the easiest way to load a remote HTML page into a string. I've just noticed though that the site you linked to loads its data via JavaScript so you're not going to have much luck unfortunately. Perhaps they offer an API you could use instead of scraping – Phil Oct 01 '18 at 01:48
  • Wait, nevermind, I should be following this correct? http://php.net/manual/en/class.domxpath.php – Syllith Oct 01 '18 at 01:48
  • The site loads its data from `https://stats.uptimerobot.com/api/status-page/2Wo6QSP4Y/1?sort=1` – Phil Oct 01 '18 at 01:50
  • They do offer an api, and unfortunately, I have no clue how to use that either. I've tried to look up how to use that one specifically, but none of its making much sense to me. https://uptimerobot.com/api I don't even know where to begin. – Syllith Oct 01 '18 at 01:50
  • Woah, that's helpful. I may be able to use that to grab the data – Syllith Oct 01 '18 at 01:51
  • Using an API is a whole lot better than trying to scrape a dynamic web page – Phil Oct 01 '18 at 01:51
  • I know I'm sounding really dumb right now, especially after I've made this whole elaborate site but am struggling on this, but do you have any tips on using the api for uptimerobot? I kind of need things spoon fed to me. I can't find any info on it and everything I look up isn't making much sense to me for this application. – Syllith Oct 01 '18 at 01:53
  • Their API docs are quite good and even include **PHP examples**. I think you want the `getMonitors` method. If you run in to some difficulty, feel free to ask a new question but please be as specific as possible – Phil Oct 01 '18 at 01:56
  • https://stackoverflow.com/questions/17234659/how-to-use-a-php-api Could I use jcubics answer and replace the address with https://stats.uptimerobot.com/api/status-page/2Wo6QSP4Y/1?sort=1 and change $_POST to something (not sure what yet)? – Syllith Oct 01 '18 at 01:58
  • Actually, this is enough info for me to find some information on my own. Thanks for the pointers. I'll have to do some more research. – Syllith Oct 01 '18 at 02:05
  • I figured it out. I had to follow the instructions under the APIv1. V2 didn't tell me anything about how to get it working. Thanks for the assistance – Syllith Oct 01 '18 at 02:35

0 Answers0