I am using BeautifulSoup4 to parse this HTML (view-source:https://weather.com/en-IN/weather/today/l/17.39,78.49) and I'm trying to retrieve temperature value. But, the value might be stored in attribute obs.temperature. I can see the temperature value "24" in the page Inspect window, but the same can't be found directly in view page source. Below is the snapshot of this problem.
From view source:
<div class="today_nowcard-temp">
<span data-gm-wx-temperature="::todayWxcardVm.obs.temperature" data-text-to-replace="{{ '[[ obs.temperature ]]'.indexOf('\[\[') !== -1 ? '--' : '[[ obs.temperature ]]' }}">[[ obs.temperature ]]</span>
</div>
From Inspect window
<div class="today_nowcard-temp">
<span data-gm-wx-temperature="::todayWxcardVm.obs.temperature" data-text-to-replace="--"><!-- ngIf: tempPrefix --> <!-- ngIf: hasValue --><span data-ng-if="hasValue" class="dir-ltr" data-ng-bind="temp | safeDisplay">24</span><!-- end ngIf: hasValue --><!-- ngIf: hasValue --><sup data-ng-if="hasValue" class="deg dir-ltr">°</sup><!-- end ngIf: hasValue --><!-- ngIf: showTempUnit -->
<!-- ngIf: !hasValue --></span>
</div>
Please let me know how to get temperature value.
Below is my Python code:
import bs4, requests
web = requests.get("https://weather.com/en-IN/weather/today/l/17.39,78.49")
websoup = bs4.BeautifulSoup(web.text, "html.parser")
print(type(websoup))
webtemperature = websoup.select("div .today_nowcard-temp span")
print(webtemperature)
print("from weather.com: "+webtemperature[0].getText()+ "degree celsius\n")
Output:
<class 'bs4.BeautifulSoup'>
[<span data-gm-wx-temperature="::todayWxcardVm.obs.temperature" data-text-to-replace="{{ '[[ obs.temperature ]]'.indexOf('\\[\\[') !== -1 ? '--' : '[[ obs.temperature ]]' }}">[[ obs.temperature ]]</span>]
from weather.com: [[ obs.temperature ]]degree celsius
