手足不一定都一樣
在影片中,你認識了相鄰兄弟選擇器與一般兄弟選擇器(+ 與 ~)。
下面這段 HTML 程式碼包含兩個標題,後面各接著一些 code 與 span 標籤:
<html>
<body>
<h2 class = 'first'>First example:</h2>
<code>some = code(2)</code>
<span>will compile to...</span>
<code>some = more_code()</code>
<h2 class = 'second'>Second example:</h2>
<code>another = code(3)</code>
<span>will compile to...</span>
<code>another = more_code()</code>
</body>
</html>
請注意,這兩個程式碼範例並沒有階層式的結構。唯一明顯的差別是各自範例前面的 h2 元素所帶的類別不同。
這段 HTML 已經為你讀入,並存放在變數 code_html 中。
本練習屬於課程
R 的網頁爬蟲
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Select only the first code element in the second example
code_html %>%
___('h2.second ___ ___')