我正在尝试检索下一个拍卖站点上的计时器以制作狙击手:
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>
我找不到正确的方法。谁能给我指路吗?
您所需要的只是 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'
浏览器中的 JavaScript 代码将所提供的 HTML 中的时间和日期转换为相对时间。
我是一名优秀的程序员,十分优秀!