Skip to content

Instantly share code, notes, and snippets.

@bbolker
Created July 23, 2024 22:34
Show Gist options
  • Save bbolker/9e7fdd535e24bb75ee7bf08e29443987 to your computer and use it in GitHub Desktop.
Save bbolker/9e7fdd535e24bb75ee7bf08e29443987 to your computer and use it in GitHub Desktop.
code to scrape the list of bright stars from Wikipedia and count by hemisphere
## https://ivelasq.rbind.io/blog/politely-scraping/index.html
## To clean data
library(tidyverse)
library(lubridate)
library(janitor)
# To scrape data
library(rvest)
library(httr)
library(polite)
url <- "https://en.wikipedia.org/wiki/List_of_brightest_stars"
url_bow <- polite::bow(url)
ind_html <-
polite::scrape(url_bow) %>% # scrape web page
rvest::html_nodes("table.wikitable:nth-child(22)") %>% # pull out specific table
rvest::html_table(fill = TRUE)
tab <- ind_html[[1]]
tab |> count(`Celestial Hemisphere`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment