python - Python BeautifulSoup 通过实时价格循环
问题描述
我正在尝试获取美国不同地点的特定商品的价格。该网站有一个文本框,您可以在其中输入状态并更新价格,但 URL 保持不变。在开发者工具中,位置会根据您更新价格的输入而改变。我正在尝试使用以下代码来获取价格:
from bs4 import BeautifulSoup
import requests
source = requests.get('https://www.sunbeltrentals.com/equipment/detail/1255/0350140/7500lb-mini-excavator/').text
soup = BeautifulSoup(source, 'lxml')
# Finding the equipment name and printing it
name_article = soup.find('div', id = 'equipment-catalog-page-container')
# This pricing is based off of typing "NC" into the search box
equipment_name = name_article.h1.text
print(equipment_name)
for price_article in soup.find_all('div', class_ = 'info--price'):
equipment_price = price_article.text
print(equipment_price)
输出是:
7,500lb Mini Excavator
Online Rate:
1 Day: {{RateDaily | toCurrency}} {{Currency}}
1 Week: {{RateWeekly | toCurrency}} {{Currency}}
4 Weeks: {{RateMonthly | toCurrency}} {{Currency}}
The displayed rates do not include the taxes or optional charges that may be selected later in the checkout process.
作为参考,开发人员工具中用于定价方面的 HTML 代码如下:
<div class="info--price" v-if="showRates">
<span class="ratesSubtitle">
Online Rate:
</span>
<br/>
<ul class="menu">
<li style="margin-right: 10px;">
1 Day:
<strong>
{{RateDaily | toCurrency}}
</strong>
{{Currency}}
</li>
<li style="margin-right: 10px;">
1 Week:
<strong>
{{RateWeekly | toCurrency}}
</strong>
{{Currency}}
</li>
<li style="margin-right: 10px;">
4 Weeks:
<strong>
{{RateMonthly | toCurrency}}
</strong>
{{Currency}}
</li>
</ul>
<small>
The displayed rates do not include the taxes or optional charges that may be selected later in the checkout process.
</small>
在开发人员工具屏幕上,它显示 {{RateMonthly | toCurrency }} 有一个价格(例如:1,125 美元),它写着 {{Currency}} 的地方写着“美元”。我不知道如何让这些在开发人员工具上显示实际价格。
我不确定它是否重要,但这里是该位置的开发人员工具:
<div id="jobsite-instance">
<jobsite-display inline-template="" v-cloak="">
<div v-if="showJobsite">
<div class="jobsite_location" v-show="!showInput">
<p>
Jobsite Location
</p>
<p style="cursor: pointer;" v-
on:click.prevent="showInput=true">
<span class="location raised">
{{currentLocation}}
</span>
<i aria-hidden="true" class="fa fa-pencil-square-o"
style="margin-left: 4px;">
</i>
</p>
</div>
<shopping-location-selector :current-
location="currentLocation" v-show="showInput">
</shopping-location-selector>
</div>
</jobsite-display>
</div>
在我的屏幕上显示 {{currentLocation}} 的位置显示“NC”。我不确定如何解决这些变量,我做错了什么吗?我的下一步将是创建一个循环来更改搜索位置,以便我可以使用它来获取不同州的价格。
解决方案
推荐阅读
- swift - 计算firebase中的用户数
- python - 无法将 Geopy 的 raw() 方法应用于 Pandas 列
- spring - 请就以下 JPA 查询问题提出建议
- excel - Excel VBA 中访问打印机对象的替代方法
- c - 索引多个数组/矩阵元素,类似于 C 中的 matlab“var[1:10]”
- c++ - 模块名称是否位于单独的“名称空间”中,或者它们是否会与变量名称发生冲突?
- java - 如何使用Java中的ArrayList在一行中创建大小为M * N的二维矩阵,其中X作为每个单元格的值?
- authentication - Flask RESTPlus API Swagger 不显示授权按钮
- php - 从 PHP 中 mdY H:i:s 格式的日期中减去 2 天
- javascript - 通过javascript使用Windows登录详细信息在网站中自动登录?如何?