V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
dbj1991
V2EX  ›  Python

去哪儿 m 版酒店价格获取,如何通过 css 计算元素的绝对定位

  •  1
     
  •   dbj1991 · 2017-04-12 11:53:06 +08:00 · 2951 次点击
    这是一个创建于 2569 天前的主题,其中的信息可能已经有所发展或是发生改变。

    去哪儿价格返回的是 html ,通过 css 定位,显示出价格。

    <div class="qt-light-orange qt-font20 qunar_mix">
          <span class="price" style="width:33px">
          <i class="qm18d6dd7e">2</i> 
          <i class="qmacf0943b">2</i> 
          <i class="qm11251921">2</i> 
          <i class="qm5c6d111c">5</i> 
          <i class="qmbd09efa2">8</i></span>
        </div>
    

    css 如下:

    .qunar_mix span.price i {
        position: absolute;
        left: 0;
        bottom: -1px;
        font-style: normal;
        background: #f0f0f0;
        height: 100%;
    }
    .qunar_mix span.price i.qm5c6d111c{left: -100px; margin-left:300px;background:none;}
    .qunar_mix span.price i.qmcf5711c8{left: -100px; margin-left:22px; padding-left:22px; background:none;}
    .qunar_mix span.price i.qmbd09efa2{left: 0px; margin-left:11px; padding-left:11px; background:none;}
    .qunar_mix span.price i.qm18d6dd7e{left: -33px; margin-left:11px; padding-left:33px; background:none;}
    .qunar_mix span.price i.qm11251921{left: -22px; margin-left:11px; padding-left:11px; background:none;}
    .qunar_mix span.price i.qmca340bd1{left: 11px; margin-left:11px; padding-left:11px; background:none;}
    .qunar_mix span.price i.qmc1c11156{left: 11px; margin-left:22px; padding-left:11px; background:none;}
    .qunar_mix span.price i.qmacf0943b{left: -100px; padding-left:300px;background:none;}
    

    最终显示的价格是 228 ,如何通过 css 来计算得到的价格呢。能想到的就是通过 phantomjs 渲染后截图,然后图片识别可以,但是效率不高

    9 条回复    2017-04-13 13:30:57 +08:00
    coo
        1
    coo  
       2017-04-12 13:09:24 +08:00
    去哪儿这招有点狠 ...
    em2046
        2
    em2046  
       2017-04-12 13:20:56 +08:00   ❤️ 2
    不显示.qunar_mix span.price i.qm5c6d111c{left: -100px; margin-left:300px;background:none;}
    200

    无 html.qunar_mix span.price i.qmcf5711c8{left: -100px; margin-left:22px; padding-left:22px; background:none;}
    -56

    显示.qunar_mix span.price i.qmbd09efa2{left: 0px; margin-left:11px; padding-left:11px; background:none;}
    22

    显示.qunar_mix span.price i.qm18d6dd7e{left: -33px; margin-left:11px; padding-left:33px; background:none;}
    11

    显示.qunar_mix span.price i.qm11251921{left: -22px; margin-left:11px; padding-left:11px; background:none;}
    0

    无 html.qunar_mix span.price i.qmca340bd1{left: 11px; margin-left:11px; padding-left:11px; background:none;}
    33

    无 html.qunar_mix span.price i.qmc1c11156{left: 11px; margin-left:22px; padding-left:11px; background:none;}
    44

    不显示.qunar_mix span.price i.qmacf0943b{left: -100px; padding-left:300px;background:none;}
    200

    加法
    然后去除 html 中没有的
    然后去除过界的
    然后根据加的结果数值排序。
    dbj1991
        3
    dbj1991  
    OP
       2017-04-12 14:26:16 +08:00
    @em2046 有效,感谢
    leeg810312
        4
    leeg810312  
       2017-04-12 15:07:18 +08:00
    不明觉厉,好奇怎么生成这样的 css
    yaoxinghui
        5
    yaoxinghui  
       2017-04-12 22:22:09 +08:00
    去哪儿我也抓过,不需要这样的,它的价格隐藏在返回的 html 的某个属性里,你认真观察下就知道了
    dbj1991
        6
    dbj1991  
    OP
       2017-04-12 22:27:19 +08:00
    @yaoxinghui <div class="qt-light-orange qt-font20 qunar_mix">
    <span class="price" style="width:33px">
    <i class="qm18d6dd7e">2</i>
    <i class="qmacf0943b">2</i>
    <i class="qm11251921">2</i>
    <i class="qm5c6d111c">5</i>
    <i class="qmbd09efa2">8</i></span>
    </div> 这就是返回的 html ,差不多半年前我也看过,是可以直接看到价格的,最近应该改了
    kfll
        7
    kfll  
       2017-04-13 00:24:32 +08:00 via Android
    …用读屏软件的遇到这些真是…
    alwayshere
        8
    alwayshere  
       2017-04-13 11:40:56 +08:00 via iPhone
    它不怕被搜索引擎降权么
    justfun
        9
    justfun  
       2017-04-13 13:30:57 +08:00
    反爬的丧心病狂啊
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5901 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 06:15 · PVG 14:15 · LAX 23:15 · JFK 02:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.