码迷,mamicode.com
首页 > Web开发 > 详细

爬虫5:Beautiful Soup的css选择器

时间:2017-01-17 23:38:34      阅读:663      评论:0      收藏:0      [点我收藏+]

标签:sel   html   color   css选择器   title   list   log   example   爬虫   

学习于:http://cuiqingcai.com/1319.html

用到的方法是 soup.select(),返回类型是 list,用 get_text() 方法来获取它的内容

 

(1)通过标签名查找

print soup.select(titleprint soup.select(a)

print soup.select(b)

 

(2)通过类名查找

print soup.select(.sister)

 

(3)通过 id 名查找

print soup.select(#link1)

 

(4)组合查找

#查找 p 标签中,id 等于 link1的内容

print soup.select(p #link1)
#直接子标签查找

print soup.select("head > title")

 

(5)属性查找

#class=“sister”的a标签

print soup.select(a[class="sister"])
print soup.select(p a[href="http://example.com/elsie"])

 

爬虫5:Beautiful Soup的css选择器

标签:sel   html   color   css选择器   title   list   log   example   爬虫   

原文地址:http://www.cnblogs.com/ronyjay/p/6295017.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!