owner888 / phpspider

《我用爬虫一天时间“偷了”知乎一百万用户,只为证明PHP是世界上最好的语言 》所使用的程序
3.49k stars 1.18k forks source link

selector没法精确选取,不管是css还是xpath #104

Open tianles opened 6 years ago

tianles commented 6 years ago
<div class="detail-journey-head">
                        <i class="icon detail-journey-day">D1</i>
                        <strong>第1天</strong>

                            <strong>北京</strong>

                                    <i class="icon detail-journey-transport-train"></i>

                                <strong>南京</strong>

                    </div>

不管是css还是xpath,都没法精确取出 “南京”

.detail-journey-head > strong:nth-child(3)

owner888 commented 6 years ago

怎么会哈,用xpath即可,写法如下: //div[contains(@class,'detail-journey-head')]/strong[3]

lypeng29 commented 5 years ago

//div[@class='detail-journey-head']/strong[last()] 还可以这样写,给自己点赞~☺ 参考:

https://www.w3school.com.cn/xpath/xpath_syntax.asp