1. 구글 Colab 온라인에서 파이썬 데이터를분석 학습할 수 있는 환경!
2. colab-1주차 연수 및 변수
2.1. 숫자 연산 특이하게 print를 사용하지 않아도 자동 계산
2.2. list 형 : 순서가 중요!
a_list = [ '1','2','3']
a_list.append('4')
a_list
a_list = {'name' : '철수' , 'age' :15},{'name' : '영희' , 'age' :25}
a_list[1]['name']
2.3. dictonary 형 : 형태가 중요
a_dict = {'nage' : '철수, 'age':15}
a_dict['height'] = 180
a_dict['height']
2.4. 함수 : 수학에서 함수와는 다름 결과 값을 나타냄
2.5. 조건문
if age > 20 :
print('성인')
else:
print('청소년')
is_adult(30)
2.6. 반복문
a_list = ['사과', '배', '감' ,'귤']
for a in a_list :
print(a)
3. 업무자동화 - 스크래핑 실습
3.1. 라이브러리 설치 하기
- !pip install bs4 requests
3.2. 웹스크래핑 기본 코드
import requests
from bs4 import BeautifulSoup
headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'}
data = requests.get('https://search.naver.com/search.naver?where=news&ie=utf8&sm=nws_hty&query=삼성전자',headers=headers)
soup = BeautifulSoup(data.text, 'html.parser')
a = soup.select_one('#sp_nws1 > div.news_wrap.api_ani_send > div > a')
lis = soup.select('#main_pack > section > div > div.group_news > ul')
for li in lis:
a = li.select_one('a.news_tit')
print(a.text, a['href'])
3.2. 크롤링기본코드
import requests
from bs4 import BeautifulSoup
def get_news(keyword):
headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'}
data = requests.get(f'https://search.naver.com/search.naver?where=news&ie=utf8&sm=nws_hty&query={keyword}',headers=headers)
soup = BeautifulSoup(data.text, 'html.parser')
lis = soup.select('#main_pack > section > div > div.group_news > ul > li')
for li in lis:
a = li.select_one('a.news_tit')
print(a.text, a['href'])
get_news('현대자동차')
get_news('LG전자')
4. 업무자동화 - 엑셀다루기
4.1. openpyxl 설치
!pip install openpyxl
'Enjoyable IT > EIT' 카테고리의 다른 글
하드웨어(Hardware) VS 소프트웨어(Software) (0) | 2019.10.30 |
---|---|
IT란 무엇인가?? (0) | 2019.10.24 |