- Install required packages
(Run once)
install.packages("rvest")
install.packages("DT")
- Load libraries
library(rvest)
library(DT)
- Specify the webpage URL (Please change the “URL” to your desired web
page)
url <- "https://darkhorsefinancial.com.au/sitemap/"
- Read the HTML content
webpage <- read_html(url)
- Extract all URLs from “a” tags
links <- webpage %>%
html_elements("a") %>%
html_attr("href")
- Create a table (data frame)
links_table <- data.frame(
URL = links,
stringsAsFactors = FALSE
)
- Create a table chart (interactive)
datatable(
links_table,
options = list(
pageLength = 10,
autoWidth = TRUE
),
caption = "Scraped URLs from Dark Horse Financial Sitemap"
)
This is the whole code for you to copy and paste
# ===============================
# 1. Install required packages
# (Run once)
# ===============================
install.packages("rvest")
install.packages("DT")
# ===============================
# 2. Load libraries
# ===============================
library(rvest)
library(DT)
# ===============================
# 3. Specify the webpage URL
# ===============================
url <- "https://darkhorsefinancial.com.au/sitemap/"
# ===============================
# 4. Read the HTML content
# ===============================
webpage <- read_html(url)
# ===============================
# 5. Extract all URLs from <a> tags
# ===============================
links <- webpage %>%
html_elements("a") %>%
html_attr("href")
# ===============================
# 6. Create a table (data frame)
# ===============================
links_table <- data.frame(
URL = links,
stringsAsFactors = FALSE
)
# ===============================
# 7. Create a table chart (interactive)
# ===============================
datatable(
links_table,
options = list(
pageLength = 10,
autoWidth = TRUE
),
caption = "Scraped URLs from Dark Horse Financial Sitemap"
)