開始使用免費開始

把這題切一切:Div 元素實作

我們已經將一份 HTML 載入到字串變數 html。在這題的兩個部分中,你會把這個 html 變數當作 HTML 文件來建立一個 Selector 物件,並建立一個可選出所有 div 元素的 SelectorList;接著,你會檢查自己對於 SelectorList 內部行為的理解。

本練習屬於課程

Python 網頁爬蟲

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

from scrapy import Selector

# Create a Selector selecting html as the HTML document
sel = Selector( ____ )

# Create a SelectorList of all div elements in the HTML document
divs = sel.xpath( ____ )
編輯並執行程式碼