Python
-
파이썬 크롤링 (Selenium / Chrome Driver) 설치하기Python 2023. 2. 3. 12:19
1. Chrome Driver 설치 우선 자신의 크롬버전을 확인 해보자 크롬을 열어서 오른쪽 상단 설정 - 도움말 - Chrome 정보 109.0.5414.120 버전을 확인할 수 있다. 그 다음은 드라이버 사이트 링크 ( https://chromedriver.chromium.org/downloads ) 에 들어가서 자신에게 맞는 버전을 찾아보자 자신의 os에 맞게 선택하면 된다. 나는 window로 사용중이므로 win32를 다운 받는다. 다운 받은 후 자신의 python 경로에 드라이버를 옮겨주면 된다. 나의 경우 c -> python 에 넣어주었다 2. Selenium 설치 cmd (명령프롬프트) 를 열어 python 파일 경로로 이동한다 나는 ' cd C:\python\Python311 ' 로 이동..
-
크롤링 (Beautiful Soup 라이브러리) - 네이버 영화 순위Python 2023. 2. 1. 17:20
네이버에서 제공하는 영화 랭킹 사이트의 데이터를 크롤링 해보자 ( 네이버 사이트 링크 : https://movie.naver.com/movie/sdb/rank/rmovie.naver?sel=cnt&date=20230131 ) import urllib.request from bs4 import BeautifulSoup from pandas import DataFrame url = 'https://movie.naver.com/movie/sdb/rank/rmovie.naver' html = urllib.request.urlopen(url) soup = BeautifulSoup(html, 'html.parser') tags = soup.findAll('div', attrs={'class':'tit3'}) pri..
-
크롤링 (Beautiful Soup 라이브러리) - 네이버 만화 읽어오기Python 2023. 2. 1. 16:22
from urllib.request import urlopen from bs4 import BeautifulSoup myurl = 'http://comic.naver.com/webtoon/weekday' # 이 페이지에 request 해서 데이터를 가져온 후 변수에 저장한다. response = urlopen(myurl) # print(type(response)) # BeautifulSoup()를 이용해서 데이터를 분석한다. soup = BeautifulSoup(response, 'html.parser') # Beautiful Soup 객체를 적절한 들여쓰기 형태로 출력해준다. # print(soup.prettify()) title = soup.find("title").string print(title)..
-
크롤링 (Beautiful Soup 라이브러리) - 선택자(selector)Python 2023. 2. 1. 12:04
css01.html 좋아하는 만화 피구왕 통키 미래 소년 코난 로보트 태권 브이 피구왕 통키 그랜다이저 로보트 태권 V 들장미 소녀 캔디 똘이 장군 과일과 야채 감 밤 대추 배 파프리카 당근 호박 양파 가지 import re from bs4 import BeautifulSoup myencoding = 'utf-8' myparser = 'html.parser' filename = 'css01.html' html = open(filename, encoding=myencoding) soup = BeautifulSoup(html, myparser) h1 = soup.select_one("div#cartoon > h1").string print("h1 = ", h1) li_list = soup.select("di..
-
크롤링 (Beautiful Soup 라이브러리) - 태그의 속성Python 2023. 2. 1. 11:53
Beautiful Soup를 사용하여 속성들의 정보를 읽어 들이고 수정해보자. ###################### fruits.html 먼저 작성하기 ###################### 사과 참외 블루베리 과일 ################################################################# from bs4 import BeautifulSoup html = open("fruits.html", "r", encoding="utf-8") soup = BeautifulSoup(html, "html.parser") body = soup.select_one("body") ptag = body.find('p') print('1번째 p태그 : ', ptag['class']..
-
크롤링 (문자열의 집합을 표현하는 정규 표현식)Python 2023. 2. 1. 11:05
특정 문자(조건)를 포함한 항목과 아닌 항목을 나누어 보자 import re # 문제1 ) 문자 a 또는 c로 시작하고, 이후 숫자 또는 알파벳이 4개로 끝나는 항목 list = ['ab123', 'cd4#6', 'cf79a', 'abc1'] regex = '[ac]{1}\w{4}' pattern = re.compile(regex) totallist = [] for item in list : if pattern.match(item) : print(item, '은(는) 조건에 적합') totallist.append(item) else : print(item, '은(는) 조건에 부적합') print('적합한 항목들') print(totallist)
-
막대 그래프(데이터 프레임) 문제4Python/맷플롯립 2023. 1. 31. 18:29
문제4) mygraph.csv 와 다음 이미지를 참고하여 코드를 작성해보세요. 이름,국어,영어 강감찬,30,35 이순신,40,45 김유신,50,50 을지문덕,30,60 김춘추,30,40 선덕여왕,30,50 import pandas as pd import matplotlib.pyplot as plt plt.rcParams['font.family'] = 'Malgun Gothic' filename = 'mygraph.csv' myframe = pd.read_csv(filename, index_col='이름', encoding='utf-8') myframe.index.name = '이름' myframe.columns.name = '시험과목' print(myframe) ymax = myframe.sum(axis..
-
막대 그래프 문제3Python/맷플롯립 2023. 1. 31. 17:45
문제) 리스트 데이터를 사용하여 막대 그래프를 그려보시오 mylist[30,20,40,30,60] 색상 참고