css和xpath选择器都无法选择到想要的元素
来源:4-7 css选择器
PhantomBlink
2021-02-28
爬取的url为https://store.ubi.com/cn/games?cgid=games&prefn1=productTypeRefinementString&prefv1=games
我想爬取左边结果的总数
从response.text和网页的源代码中都能直接找到对应的代码段
<div class="pagination">
<div class="results-hits">
<span class="toggle-grid"><i class="fa fa-th fa-lg" data-option="column"></i><i class="fa fa-th-list fa-lg" data-option="wide"></i></span>
<p><span>182</span> 个结果</p>
</div>
</div>
但是通过css和xpath都没有获取到这一个div,甚至直接获取全部div结果中也只有不到30结果而且不包含这一个div,只能通过正则去获取。
希望老师能解释一下为何两个选择器都无法获取,谢谢!
代码补充:
res = requests.get(url="https://store.ubi.com/cn/games?cgid=games&prefn1=productTypeRefinementString&prefv1=games")
sel = Selector(response = res)
a = sel.css(".pagination").extract() #结果为空list
b = sel.css("div").extract() #结果为长度28的list,但不包含上述div
c = sel.css("span").extract() #结果为长度9的list,但不包含上述span
print(res.text) #打印出来可以找到上述代码段

写回答
1回答
-
如果想要定位这种问题 你需要打印出来html 然后自己看看html中是否有这个路径 不要值通过f12查看
052021-03-04
相似问题