Select multiple HTML types
As you have seen in the video, CSS can be used to style a web page. In the most basic form, this happens via type selectors, where styles are defined for and applied to all HTML elements of a certain type. In turn, you can also use type selectors to scrape pages for specific HTML elements.
As demonstrated in the video, you can also combine multiple type selectors via a comma, i.e. with html_elements("type1, type2"). This selects all elements that have type1 or type2.
Have a look at the following HTML:
<html>
<body>
<div>Python is perfect for programming.</div>
<p>Still, R might be better suited for data analysis.</p>
<small>(And has prettier charts, too.)</small>
</body>
</html>
The raw HTML code is provided to you in the variable languages_raw_html.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Web Scraping in R
अभ्यास निर्देश
- Read in
languages_raw_html. - Using the method shown above, select all
divandpelements in this HTML.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Read in the HTML
languages_html <- ___
# Select the div and p tags and print their text
languages_html %>%
___ %>%
html_text()