НачатьНачать бесплатно

Scrape an element based on its text

As shown in the video, the text() function also allows you to select elements (and their parents) based on their text. Here's an ordered list:

<h3>The rules of programming</h3>
<ol>
  <li>Have <em>fun</em>.</li>
  <li><strong>Don't</strong> repeat yourself.</li>
  <li>Think <em>twice</em> when naming variables.</li>
</ol>

In this exercise, your goal is to extract the li element where "twice" is emphasized.

You might think that, here, it would be much easier to apply a CSS selector like li:last-child, but wait until you finish this exercise…

programming_html contains the above HTML document.

Это упражнение является частью курса

Web Scraping in R

Посмотреть курс

Интерактивное практическое упражнение

Попробуйте выполнить это упражнение, дополнив этот пример кода.

# Select all li elements
programming_html %>%
	html_elements(___ = ___)
Редактировать и запускать код