เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

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 div and p elements in this HTML.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Read in the HTML
languages_html <- ___
# Select the div and p tags and print their text
languages_html %>%
	___ %>%
	html_text()
แก้ไขและรันโค้ด