在python中,我如何获取第五行的值,而不是第二行的值

问题描述 投票:0回答:1

在网站上,我有此源代码

            <div class="estimated-delivery">
<input id="currentCity" type="hidden" value="City">
<input id="currentCityISO" type="hidden" value="CY">
<input id="idUnit" type="hidden" value="3910200523">
<input id="availableOffers" type="hidden" value="4">

而且我用python写的

lastvalue = page_soup.find("div", {"class": "estimated-delivery"})
lastvalue.input["value"] 

结果回来了

'City'

我不需要网站源代码第二行中的第一个值,我需要网站源代码中第五行的值是

'4'

谢谢

python
1个回答
0
投票
我会发现此选项容易得多:

last_value = soup.find("input", {"id": "availableOffers"}) last_value = last_value["value"]

否则,请尝试:

last_value = soup.find_all("div", {"class": "estimated-delivery"}) last_value = last_value[3].input["value"]

© www.soinside.com 2019 - 2024. All rights reserved.