Titular
和前一課的練習相似,這裡要你使用預先載入、名為 response 的 Response 物件,從(精簡版的)DataCamp 課程目錄 https://www.datacamp.com/courses/all 擷取課程標題。要完成這項任務,你只需要知道:
- 課程標題就是 HTML 文件中所有
h4元素的文字內容。
請在此處把這些課程標題擷取出來。
本練習屬於課程
Python 網頁爬蟲
練習說明
- 使用
response,將選到的課程標題元素組成的SelectorList指派給變數crs_title_els。 - 將從
crs_title_els萃取出的課程標題文字建立成清單,並指派給變數crs_titles。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create a SelectorList of the course titles
crs_title_els = ____
# Extract the course titles
crs_titles = ____
# Print out the course titles
for el in crs_titles:
print( ">>", el )