越簡單越好!
沿用上一題相同的 HTML…
<html>
<body>
<div class="first section">
A text with a <a href="#">link</a>.
</div>
<div class="second section">
Some text with <a href="#">another link</a>.
<div class="first paragraph">Some text.</div>
<div class="second paragraph">Some more text.
<div>...</div>
</div>
</div>
</body>
</html>
…你能用一個更精簡的選擇器,選出「和前一題相同的三個節點」嗎?
變數 complicated_html 已經為你準備好。它包含了上面原始碼的整份 HTML 文件。
本練習屬於課程
R 的網頁爬蟲
練習說明
- 建立一個簡單的選擇器,選出
div.second.section的三個「所有」後代。 - 這個選擇器應該只由「兩個」
div類型選擇器加上一個空白組成,總長度正好是 7 個字元!
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Select the three divs with a simple selector
complicated_html %>%
html_elements(___)