0

I am creating a simple webpage with a calender showing today's date. On this webpage, I also want to put a button that, once clicked, displays the name of a famous person whose birthday it is on this day. To do this, I want to get data from famousbirthdays.com. I have noticed a pattern with the urls on this site and to get the birthdays for any day, all I have to do is type

"https://www.famousbirthdays.com/" + month + day + ".html"

However, I am completely lost at what to do from here. So far, I have done this, but it doesn't work:

function celebBirthday(){

  var url = "https://www.famousbirthdays.com/";
  var birthday = currentMonth.toLowerCase() + "" + currentDate;

  // gets famous birthdays page of current date using JQuery (I think)
  $.get(url + birthday + ".html", function(response) {
    console.log(response);
  });

  // "name" is the div class I am looking for
  var name = $(response).find("name");

  // should set the <p> tags to the celebrity's name
  setText("celebName", name);

}

I know I am making a mistake in getting the class name. Currently, I am using the inspect element function on the website to see the html. How do I specify that I want the name of the first person on that webpage (i.e the most famous person whose birthday it is that day) ?

Zelda
  • 47
  • 1
  • 10
  • Have you tried looping through all the names and choosing the first one? – bryanx Feb 03 '18 at 03:21
  • @bryanx how would I begin to do this? I am new to web scraping and don't know how to get access to the things on the webpage – Zelda Feb 03 '18 at 03:34

1 Answers1

0

They dont have an open API, so they wont reply to a different webpage. In order to do this, you will need a backend to get the value and pass it to your frontend. The other option is to manually get 365 names, and load them into your page

iagowp
  • 2,428
  • 1
  • 21
  • 32
  • Is there no way to do this with just javascript, html, and css? I am new to coding and don't want to take on too many things at once :) – Zelda Feb 03 '18 at 03:35
  • @Zelda well, there is, in a way. You could use javascript on your backend, using node. but on the scrapping part, no there isnt. The only way that would be possible would be if they had an API – iagowp Feb 03 '18 at 04:17