이 간단한 Web Weather Scraping
스크립트를 함께 사용하여 주어진 위치의 온도를 확인합니다. 코드가 완벽하게 작동하지만 최상의 또는 가장 깨끗한 버전이 아닐 수도 있습니다. 아직도 배우기. 그러나 그것은 <span _ngcontent-c19="" class="wu-value wu-value-to">67</span>
에서 HERE까지 근근이 살아가고 있습니다.루프 인 함수의 경우, 이해하기가 어려울 때
#!/usr/bin/python
# -*- coding: utf-8 -*-
import requests
from BeautifulSoup import BeautifulSoup
import time
degree = u'\N{DEGREE SIGN}'
url = 'https://www.wunderground.com/weather/us/ca/san-diego/KCASANDI355'
response = requests.get(url)
html = response.content
soup = BeautifulSoup(html)
current_temp = soup.find("div", {"class" : "current-temp"}).find("span", {"class" : "wu-value wu-value-to"})
for i in current_temp:
print('San Diego Feels Like ') + i + (degree + 'F')
출력은 다음과 같습니다 : 여기
San Diego Feels Like 74°F
내 목표는 예제의 경우에 대한 인쇄 current_temp
변수에 정의 된 현재 온도에 따라 반복하는 기능을 가지고 있으며, 온도가 70F It's too cold
, 또는 80F를 넘는 경우 It is too hot
등 그러나 내 코드를 실행하는 방법을 이해하는 데 문제가 있거나이 경우 print
이러한 다양한 작업이나 방법을 말할 수 있습니까? 실례합니다. While (True):
루프에는 분명히 잘못된 것이 있지만 그 주위에 머리를 들이지 못합니다. 어떤 도움을 주셔서 감사합니다. 모든
#!/usr/bin/python
import requests
from BeautifulSoup import BeautifulSoup
import time
degree = u'\N{DEGREE SIGN}'
url = 'https://www.wunderground.com/weather/us/ca/san-diego/KCASANDI355'
response = requests.get(url)
html = response.content
soup = BeautifulSoup(html)
current_temp = soup.find("div", {"class" : "current-temp"}).find("span", {"class" : "wu-value wu-value-to"})
def weather():
while(True):
for i in current_temp:
print('San Diego Feels Like ') + i + (degree + 'F')
#time.sleep(2)
if (i <= 70) and (i >= 50):
print('It\'s kinda cool')
break
elif i <= 50:
print('It\'s cold af')
elif (i >= 80) and (i <= 100):
print('It\'s hot af')
break
else:
print('You Dead')
break
if __name__ == "__main__":
weather()
'i'는 문자열이지만 다른 정수와 비교할 때 정수 여야합니다. –