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
原文地址:https://www.cnblogs.com/bamboozone/p/10423872.html