美文网首页
xpath使用

xpath使用

作者: Rokkia | 来源:发表于2018-07-23 17:55 被阅读34次

    class 为 ctx-box J_MouseEneterLeave J_IconMoreNew 的div标签

    title_elems = response.xpath('//div[@class="ctx-box J_MouseEneterLeave J_IconMoreNew"]')
    

    class为ctx-box J_MouseEneterLeave J_IconMoreNew的div标签 下的 class为row row-2 title的div标签 下的 所有的a标签 的 data-nid 属性的值

    good_ids = response.xpath('//div[@class="ctx-box J_MouseEneterLeave J_IconMoreNew"]/div[@class="row row-2 title"]/a/@data-nid').extract()
    

    id为J_AttrUL的ul标签下的所有li的内容集合

    attributes = response.xpath('//ul[@id="J_AttrUL"]/li/text()').extract()
    

    获取值

    extract() 获取值得集合
    extract_first()  获取集合里面的第一个
    

    获取标签内容

    sel.xpath("//h1/text()").extract()
    

    相关文章

      网友评论

          本文标题:xpath使用

          本文链接:https://www.haomeiwen.com/subject/qmxxcftx.html