gpt4 book ai didi

python - 如何使用 Beautifulsoup Python 检索拍卖时间

转载 作者:太空宇宙 更新时间:2023-11-03 17:57:26 25 4
gpt4 key购买 nike

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

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 中的时间和日期转换为相对时间。

关于python - 如何使用 Beautifulsoup Python 检索拍卖时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28287070/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com