V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
U87
V2EX  ›  问与答

原谅我这个伸手党

  •  1
     
  •   U87 · 2018-04-19 14:32:35 +08:00 · 2320 次点击
    这是一个创建于 2170 天前的主题,其中的信息可能已经有所发展或是发生改变。

    这个用 xpath 怎么取出 totalSize 呀

    17 条回复    2018-04-24 13:22:22 +08:00
    U87
        1
    U87  
    OP
       2018-04-19 14:35:33 +08:00
    <div id="TestView_pageableDiv" class="m-pagination" style="font-family: 'Microsoft YaHei';" totalSize="19790" pageSize="20" currPage="2">

    </div>
    这个哈谢谢啦
    alex321
        2
    alex321  
       2018-04-19 14:42:05 +08:00
    document.getElementById('TestView_pageableDiv').getAttribute('totalSize');
    maichael
        3
    maichael  
       2018-04-19 14:48:10 +08:00
    如果有这个页面的话,进控制台看元素,右键复制 XPath 就好
    animal
        4
    animal  
       2018-04-19 14:56:09 +08:00 via Android
    //div[contains(@id,'TestView_pageableDiv']/@totalSize
    U87
        5
    U87  
    OP
       2018-04-19 15:18:24 +08:00
    @animal 不对啊,报错了。。
    F1024
        6
    F1024  
       2018-04-19 15:18:54 +08:00
    <div class="item-pic">
    <a href="//2.taobao.com/item.htm?id=560088094729" target="_blank" title=" [转卖] 创得 小米 5 手机壳小米 5s 保护套小米 6 防摔硅</a>
    </div>


    txt4 = txt.xpath('//div/div[@class="item-info"]/div/a')

    print(txt4[0].attrib.get('title'))
    F1024
        7
    F1024  
       2018-04-19 15:19:53 +08:00
    这个问题我也问过 XD
    U87
        8
    U87  
    OP
       2018-04-19 15:21:32 +08:00
    url = ''''''
    data = {"currPage":1, "typeId":30091, "pageSize":20}
    r1 = requests.post(url=url, data=data).text
    r = etree.HTML(r1)
    max_count = r.xpath('//div[id="TestView_pageableDiv"]/@totalSize')
    print(max_count)
    我这样按理说是可以获取到的,到始终为空
    ioven
        9
    ioven  
       2018-04-19 15:26:13 +08:00
    ![]( https://i.loli.net/2018/04/19/5ad84450b2a25.png)

    totalSize 取不到值,只能用小写 totalsize
    U87
        10
    U87  
    OP
       2018-04-19 15:51:28 +08:00
    @ioven 卧槽,老哥这是什么原理,为啥小写就行啊?
    animal
        11
    animal  
       2018-04-19 17:07:08 +08:00 via Android
    @U87 手机打的,少了个反括号
    U87
        12
    U87  
    OP
       2018-04-19 17:46:02 +08:00
    @animal 恩,为啥要小写
    ioven
        13
    ioven  
       2018-04-19 19:01:21 +08:00
    @U87 没研究过 lxml 的源码,怀疑是 dom 标准化处理时将所有属性名小写了
    U87
        14
    U87  
    OP
       2018-04-20 10:13:54 +08:00
    @ioven 好的,我自己研究下,谢啦,老哥,好人一生平安
    U87
        15
    U87  
    OP
       2018-04-20 15:27:59 +08:00
    @F1024 谢谢现在解决了
    leopku
        16
    leopku  
       2018-04-20 16:55:45 +08:00
    原谅我这一生不写光伸手,也会怕有一天会删库。。。
    U87
        17
    U87  
    OP
       2018-04-24 13:22:22 +08:00
    @leopku 尼玛。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3712 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 10:40 · PVG 18:40 · LAX 03:40 · JFK 06:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.