U87
V2EX  ›  问与答

原谅我这个伸手党

  •  1
     
  •   U87 · Apr 19, 2018 · 3451 views
    This topic created in 3141 days ago, the information mentioned may be changed or developed.

    这个用 xpath 怎么取出 totalSize 呀

    17 replies  •  2018-04-24 13:22:22 +08:00
    U87
    U87
    OP
    Apr 19, 2018
    1
    <div id="TestView_pageableDiv" class="m-pagination" style="font-family: 'Microsoft YaHei';" totalSize="19790" pageSize="20" currPage="2">

    </div>
    这个哈谢谢啦
    alex321
    alex321
    Apr 19, 2018
    2
    document.getElementById('TestView_pageableDiv').getAttribute('totalSize');
    maichael
    maichael
    Apr 19, 2018
    3
    如果有这个页面的话,进控制台看元素,右键复制 XPath 就好
    animal
    animal
    Apr 19, 2018 via Android
    4
    //div[contains(@id,'TestView_pageableDiv']/@totalSize
    U87
    U87
    OP
    Apr 19, 2018
    5
    @animal 不对啊,报错了。。
    F1024
    F1024
    Apr 19, 2018
    6
    <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
    F1024
    Apr 19, 2018
    7
    这个问题我也问过 XD
    U87
    U87
    OP
    Apr 19, 2018
    8
    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
    ioven
    Apr 19, 2018
    9
    ![]( https://i.loli.net/2018/04/19/5ad84450b2a25.png)

    totalSize 取不到值,只能用小写 totalsize
    U87
    U87
    OP
    Apr 19, 2018
    10
    @ioven 卧槽,老哥这是什么原理,为啥小写就行啊?
    animal
    animal
    Apr 19, 2018 via Android
    11
    @U87 手机打的,少了个反括号
    U87
    U87
    OP
    Apr 19, 2018
    12
    @animal 恩,为啥要小写
    ioven
    ioven
    Apr 19, 2018
    13
    @U87 没研究过 lxml 的源码,怀疑是 dom 标准化处理时将所有属性名小写了
    U87
    U87
    OP
    Apr 20, 2018
    14
    @ioven 好的,我自己研究下,谢啦,老哥,好人一生平安
    U87
    U87
    OP
    Apr 20, 2018
    15
    @F1024 谢谢现在解决了
    leopku
    leopku
    Apr 20, 2018
    16
    原谅我这一生不写光伸手,也会怕有一天会删库。。。
    U87
    U87
    OP
    Apr 24, 2018
    17
    @leopku 尼玛。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1953 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 15:27 · PVG 23:27 · LAX 07:27 · JFK 10:27
    ♥ Do have faith in what you're doing.