【问题标题】:How to retrieve Auction-Time with Beautifulsoup Python如何使用 Beautifulsoup Python 检索拍卖时间
【发布时间】:2015-02-02 21:26:31
【问题描述】:

我正在尝试在下一个拍卖网站上检索计时器以制作狙击手:

http://www.vakantieveilingen.nl/veiling-van-de-dag.html

我需要获取拍卖时间,我可以在以下位置找到:

<div class="auction-time"> 
  <span class="h-init h-time-tick 
        ng-valid ng-binding ng-dirty" 
        ng-hide="popup.laughingSecondPrice > 0"
        ng-model="auction.time" ng-bind-html="auction.time.left|timeLeftFormatForBiedWidget"
        h-model-name="expires"><strong>03</strong><i>:</i><strong>31</strong>
  </span> 
  <span ng-show="popup.laughingSecondPrice > 0" class="ng-hide">Gesloten</span>
</div>

我找不到正确的方法。谁能给我指路?

【问题讨论】:

    标签: python web-crawler beautifulsoup


    【解决方案1】:

    您只需要一个CSS selector 即可使用auction-time 类获取div 元素中的span 元素:

    auction_time_span = soup.select('.auction-time span.h-time-tick')[0]
    print(auction_time_span.get_text())
    

    element.get_text() function 然后返回包含的字符串值。

    演示:

    >>> import requests
    >>> from bs4 import BeautifulSoup
    >>> response = requests.get('http://www.vakantieveilingen.nl/veiling-van-de-dag.html')
    >>> soup = BeautifulSoup(response.content)
    >>> soup.select('.auction-time span.h-time-tick')[0].get_text()
    u'2015-02-02T22:32:00+01:00'
    

    提供的 HTML 中的时间和日期由浏览器中的 Javascript 代码转换为相对时间。

    【讨论】:

    • u'2015-02-02T22:32:00+01:00' 与拍卖结束时间不同 (?) 还是我错了
    • @FrEaKi:这就是提供给浏览器的 HTML 中包含的内容。 Javascript 代码 可能会改变它的显示。
    • @FrEaKi:你期望的价值是什么?
    • 我期待每次迭代(每 1 秒):03:31 然后去掉这个我有 3.31
    • @FrEaKi:您的浏览器采用 ISO 8601 时间戳并将其转换为相对时间。你可以在 Python 中做同样的事情。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多