본문 바로가기

전체 글47

Python 크롤링, 동적으로 가져오기 selenium # crawler.py import ssl import sys from urllib.request import Request, urlopen from datetime import datetime from bs4 import BeautifulSoup def crawling(url='', encoding='utf-8', proc1=lambda data :data, proc2=lambda data :data, err = lambda e : print(f'{e}: {datetime.now()}',file=sys.stderr) ) : try : request = Request(url) ssl._create_default_https_context = ssl._create_unverified_context() con.. 2019. 6. 19.
Python 크롤링 연습 프로젝트 - setting - project -> + 모양 -> beautifulSoup4 설치 from bs4 import BeautifulSoup html = ''' 기생충 ''' # 1. tag 조회 def ex1(): bs= BeautifulSoup(html, 'html.parser') print(bs) print(type(bs)) if __name__ == '__main__': ex1() >> 기생충 # 1. tag 조회 def ex1(): bs= BeautifulSoup(html, 'html.parser') # print(bs) # print(type(bs)) tag=bs.td print(tag) print(type(tag)) >> 기생충 tag = bs.a print(tag) print(ty.. 2019. 6. 18.
Python 클래스(1) 클래스, 인스턴스 메서드/ 멤버, 인스턴스 변 # class Point class Point: count_of_instance = 1000 def setx(self, x): self.x = x def sety(self, y): self.y = y def getx(self): return self.x def gety(self): return self.y def show(self): print(f'점[{self.x}, {self.y}]를 그렸습니다.') @classmethod def class_method(cls): return cls.count_of_instance @staticmethod def static_method(): print('static method clalled') > self라는 자기자신을 넣어줘야함 | bound instance M.. 2019. 6. 17.
Python 파일입출력 예제 import sys print(1) print('hello',' ','hello') # sep 파라미터 x =0.2 s='hello' print(str(x)+' ',s) print(x,s,sep=' ') # 기본적인 print() print(sep=' ',end='\n') # file 파라미터를 지정 print('hello world',file=sys.stdout) print('error: hello wold',file=sys.stderr) # file 출력 f=open('hello.txt','w') print( type(f) ) print('hello world',file=f) f.close() # 참고 sys.stdout.write('Heloo wORld?~') #textmode 가 default :.. 2019. 6. 17.
Python 모듈, import python 모듈 파이썬 프로그램 파일로 따로 함수나 변수를 정의 한다 파이썬 스크립트를 작성할 때 매번 비슷한 클래스, 함수 코드의 중복을 피하기 위해 공통 부분을 따로 빼서 모듈과 패키지로 만든다 모듈 : 변수, 함수, 클래스 등을 모아 놓은 스크립트 파일 패키지 : 여러 모듈을 묶은 것 모듈 검색 경로 import sys print(sys.path) > D:\PycharmProject\python_ch2.7, ... 모듈은 특정 디렉토리에서 찾게 된다. 실행되는 모듈의 위치는 기본적으로 포함된다 다른 프로젝트에 있는 모듈 가져오기 import sys sys.path.append('D:/PycharmProject/python-modules') print(sys.path) import mymath pr.. 2019. 6. 17.
Python 기초 str, tuple 등.. import sys print(sys.argv) args = sys.argv[1:] print(args) # 생성 d= {'basketball':5,'baseball':9} print(d,type(d)) # 변경가능 d['valleyball']=6 print(d) # 반복(*) , 연결(+) 지원하지 않는다 # (sequence 형이 아니기 때문에) print(len(d)) # in, not in 가능 : 키만 가능 print('soccer' in d) print('valleyball' in d) # 다양한 dict 객체 생성 방법 # 1. literal d=dict(one=1,two=2,three=3) print(d) # 2. dict() 사용하는 방법 d=dict([('one',1),('two',2).. 2019. 6. 13.
Python 기초 #설치 파이썬의 VCS (version control system) import -> git으로 올리겠다 checkout -> 끌어 오겠다 작성시에는 vim 모드로 했으니 i 를 누르고 작성해야 글이 쳐진다! alt + enter 는 import ! # Hello py print('hello world') def add(m,n): s=m s+=n return s def max(m,n): if(m>n) : return m else : return n a=1 b=1 a=2 if a>1 : print('big') print('big') for i in range(1,10) : print('--> ',i) print('end!') # 변수 이름은 문자, 숫자, _로 구성된다. import keyword frie.. 2019. 6. 12.
스프링 시작 - 메이븐 프로젝트 생성 Maven으로 스프링 프로젝트 폴더 만들기 스프링을 시작하기 위해서는 스프링 부트, STS 플러그인 등 여러가지 방법이 있다. 스프링은 환경설정 부분이 제일 오래 걸리고 중요한 부분! 스프링 프로젝트를 생성하기 위해서는 Maven을 사용한다 Maven은 war 또는 jar 파일을 build, 라이브러리 의존성 (dependency) 해결, 컴파일 , 배포 등을 해결해주는 도구이다. * 컴파일이란? 컴파일이란 컴퓨터가 이해할 수 있는 언어로 바꿔주는 과정. 목적파일이 생겨남 * 링크란? A라는 소스 파일에서 B라는 소스파일에 존재하는 함수를 호출하는 경우가 있다. 이때 A와 B 소스파일 각각을 컴파일만 하면 A가 B에 존재하는 함수를 찾지 못하기 때문에 호출할 수 없다. 이 A와 B를 연결해주는 작업이 ".. 2019. 6. 8.