我使用BeautifulSoup4来解析这个HTML(查看源:https://weather.com/en-IN/weather/today/l/17.39,78.49),我试图检索温度值。但是,该值可能存储在属性obs.temperature中。我可以在Inspect窗口中看到温度值“24”,但在查看页面源中不能直接找到。以下是这个问题的快照。无法使用beautifulsoup模块从HTML检索温度值python
从视图源:
[[ obs.temperature ]]
从检查窗
24°
请让我知道如何获得温度值。
下面是我的Python代码:
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")
输出:
[[[ obs.temperature ]]]
from weather.com: [[ obs.temperature ]]degree celsius
+0
如果它只是为了获得API的一个城市,你为什么不使用http ://openweathermap.org/api –
+0
这个页面通过AJAX请求获得温度,所以beautifulsoup不起作用。您将通过Selenium实现这一目标,或者您可以监控网络流量并执行与本网站相同的请求 –
+0
我已经开始学习使用python进行网络抓取并发现了一篇美丽的文章。所以,我用同样的方法描述了作者,我不知道Selenium或其他工具。将进一步阅读有关Selenium的内容,并尝试是否可以帮助获取温度。 –