Code Lion Python3
파이썬3
1. BeautifulSoup
- module
- 내장함수
- 변수.findall(‘찾을문자’, ‘찾을문자2’) : 데이터를 찾는 함수
- bs4 (BeautifulSoup)
- BeautifulSoup( 가공할 데이터, 가공 방법 ) :데이터를 가공하는 함수
- requests
- requests.get( url ) : url을 get하는 함수
- datetime(datetime)
- 내장함수
-
BeatifulSoup(데이터, 파싱방법)
-
BeatifulSoup(response.text, ‘html.parser’)
request 라이브러리 설치 : pip install requests
```python import requests from bs4 import BeautifulSoup
url = "http://www.daum.net/" response = requests.get(url) # print(response.text[:500]) soup = BeautifulSoup(response.text, 'html.parser') print(soup.title) ```
2. WhetherAPI
- Application Programming Interface
- OPEN API : 무료 API
- API KEY : 누가 사용하는지 알기 위함
- f String
import requests import json city = "Seoul" apikey = "####################################" api = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={apikey}" result = requests.get(api) print(result.text) data = json.loads(result.text) # 텍스트를 javascript object notation(키:밸류)로 변경 # print(type(result.text)) # print(type(data)) print(data["name"],"의 날씨입니다.") print("날씨는 ",data["weather"][0]["main"],"입니다.") print("현재 온도는 ",data["main"]["temp"],"입니다.") print("하지만 체감 온도는 ",data["main"]["feels_like"],"입니다.") # 최저 기온 : main - temp_min print("최저 기온은 ",data["main"]["temp_min"],"입니다.") # 최고 기온 : main - temp_max print("최고 기온은", data["main"]["temp_max"], "입니다.") # 습도 : main - humidity print("습도는", data["main"]["humidity"], "입니다.") # 기압 : main - pressure print("기압은", data["main"]["pressure"], "입니다.") # 풍향 : wind - deg print("풍향은", data["wind"]["deg"], "입니다.") # 풍속 : wind - speed print("풍속은", data["wind"]["speed"], "입니다.")
댓글남기기