• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
oooooolr
You can do anything but not everything. ——David Allen
博客园    首页    新随笔    联系   管理    订阅  订阅

css选择问题

<div class="col-lg-4 col-md-6 mb-4">
<div class="card">

<a href="/exercise/list_basic_detail/90008-E/"><img class="card-img-top img-fluid" src="/static/img/90008-E.jpg" alt=""></a>

<div class="card-body">
<h4 class="card-title">
<a href="/exercise/list_basic_detail/90008-E/">Short Dress</a>
</h4>
<h5>$24.99</h5>
</div>

</div>
</div>

css('div .col')选取不到对象,返回空列表

css('div[class*=col]')可以返回对象

or xpath('//div//a[contains(@href,"list")]可以返回,此处注意"list"not'list'双引号
response.css('.pagination li:nth-child(9)::attr(href)').get() 选区不到href的值,去掉)::attr(href)可以返回到正确的li
response.css('.pagination li:nth-child(9)').re('href="(.*?)"')可以提取出来,re之后不用加get()
response.css('.pagination li:nth-child(9)').re('href="(.*?)"')返回是列表,不能直接用response.follow,在
response.css('.pagination li:nth-child(9)').re('href="(.*?)"')[0]提取出值
response.css('a[class*=page]:contains("Next")').re('href="(.*?)"')[0]  。。。。contains() will match elements with the desired text block:,后面的“:”要紧跟,不要有空格

 

 

 

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- focus on what you want to be
posted @ 2019-02-23 19:32  oooooolr  阅读(179)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3