Heim  >  Fragen und Antworten  >  Hauptteil

python - pyspider 如何获取某个列表中的第n个元素

response.doc('.link_nei>ul>li>a').items()
上面的语句是用来获取所有符合条件的 <a>,我想获得倒数第二个 <a> 应该怎么获得? 教程上都是通过正则表达式去筛选,不过这种方法好 low 而且不实用

黄舟黄舟2741 Tage vor537

Antworte allen(2)Ich werde antworten

  • PHPz

    PHPz2017-04-18 10:33:15

    response.doc('.link_nei>ul>li>a').eq(-2).items()
    

    参考 pyquery 的文档 https://pythonhosted.org/pyqu...

    Antwort
    0
  • PHP中文网

    PHP中文网2017-04-18 10:33:15

    我看你在用CSS选择器,a后面加上:nth-last-child(2)即可。

    CSS选择器教程:http://www.w3school.com.cn/cs...

    Antwort
    0
  • StornierenAntwort