标题党
与上一课的练习类似,您将使用一个预加载的 Response 对象 response,从 DataCamp 课程目录(精简版)https://www.datacamp.com/courses/all 中抓取课程标题。要顺利完成,您只需知道以下信息:
- 课程标题是 HTML 文档中所有
h4元素的文本。
请在此提取这些课程标题。
本练习是课程的一部分
Python Web 爬取
练习说明
- 使用
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 )