Ask Your Question
4

How can I use R Studio to perform web scraping of information about the Joseon Dynasty from Wikipedia?

asked 2022-09-05 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-03-24 22:00:00 +0000

ladyg gravatar image

To perform web scraping of information about the Joseon Dynasty from Wikipedia using R Studio, you can follow these steps:

  1. First, you need to install the "rvest" package in R Studio. You can do this by typing the following command in the console:

.packages("rvest")

  1. After installing the package, load it into your R session with this command:

(rvest)

  1. Next, you can use the read_html() function to retrieve the HTML content of the Wikipedia page about the Joseon Dynasty:

<- "https://en.wikipedia.org/wiki/Joseon"

<- read_html(url)

  1. Once you have the HTML content, you can use the html_nodes() function to select specific elements from the page. For example, you can use the following code to retrieve all the headings on the page:

<- page %>% html_nodes("h2, h3") %>% html_text()

  1. To retrieve a specific section of the page, you can use the html_node() function with a CSS selector to select the relevant element. For example, to retrieve the "Culture" section, you can use this code:

_section <- page %>% html_node("#Culture") %>% html_text()

  1. You can also use the html_table() function to extract tables from the page. For example, to retrieve the table of Joseon Dynasty kings, you can use this code:

_table <- page %>% html_nodes("table.wikitable")[[1]] %>% html_table()

  1. Finally, you can use the retrieved data for further analysis and visualization in R Studio.
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-09-05 11:00:00 +0000

Seen: 13 times

Last updated: Mar 24 '23