शुरू करेंमुफ़्त में शुरू करें

Get to know the position() function

As you saw in the video, the position() function is very powerful when used within a predicate. Together with operators, you can basically select any node from those that match a certain path.

You'll try this out with the following HTML excerpt that is available to you via rules_html. Let's assume this is a continuously updated website that displays certain Coronavirus rules for a given day and the day after.

...
<div>
  <h2>Today's rules</h2>
  <p>Wear a mask</p>
  <p>Wash your hands</p>
</div>
<div>
  <h2>Tomorrow's rules</h2>
  <p>Wear a mask</p>
  <p>Wash your hands</p>
  <small>Bring hand sanitizer with you</small>
</div>
...

यह अभ्यास पाठ्यक्रम का हिस्सा है

Web Scraping in R

पाठ्यक्रम देखें

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Select the text of the second p in every div
rules_html %>% 
  html_elements(xpath = ___) %>%
  ___
कोड संपादित करें और चलाएँ