Skip to content

Instantly share code, notes, and snippets.

@guillaumeguerin
Created August 9, 2018 13:47
Show Gist options
  • Select an option

  • Save guillaumeguerin/173e8d3687df38aa4f2cb38e7794c555 to your computer and use it in GitHub Desktop.

Select an option

Save guillaumeguerin/173e8d3687df38aa4f2cb38e7794c555 to your computer and use it in GitHub Desktop.
Weather Scraper
//Example url : https://www.timeanddate.com/weather/?continent=europe
var cityName = "";
var weather = "";
var temperature = "";
var rows = document.getElementsByTagName("tbody")[0].getElementsByTagName("tr");
for(i=0; i<rows.length; i++) {
cityName = rows[i].children[0].innerText.replace(" *","");
weather = rows[i].children[2].children[0].getAttribute("alt");
temperature = rows[i].children[3].innerText.replace(" °C","");
console.log(cityName + ";" + weather + ";" + temperature);
}
@guillaumeguerin
Copy link
Author

guillaumeguerin commented Aug 9, 2018

Example :

A Coruña;Passing clouds. Mild.;20 °C
Aachen;Rain showers. Broken clouds. Mild.;21 °C
Aalborg;Passing clouds. Mild.;24 °C
Aalen;Passing clouds. Hot.;33 °C
Aalst;Rain. Cloudy. Mild.;17 °C
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment