Beautiful Soup download : http://www.crummy.com/software/BeautifulSoup install : >>>python setup.py install >>> html = """ test web text contents """ find() , find_all()from bs4 import BeautifulSoupbs = BeautifulSoup(html)print(bs.prettify())bs.find('title')# 인수의 태그를 가지고 온다. bs.find_all('p')# 해당 태그를 한꺼번에 가지고 온다 head_tag = bs.find('head')# html 내에서 부분의 객체를 리턴head_tag.find('title')# 찾아냄head_tag.fi..
파일 생성 및 수정 모드t : 텍스트(default), b : 바이너리, r : 일기(default), w : 쓰기, a : 이어쓰기, + 읽기 , 쓰기 f = open('test.txt', 'w')f.write('텍스트에 저장될 문자열') // write함수 다음에 오는 수는 글자수이다print("텍스트에 저장할 문자열" ,file=f)f.close()파일 자동의 닫기 with open('test.txt', 'a') as test : test.write('\n 입력될 문자열') 읽기f = open('test.txt', 'r')f.readline() # 한번에 한줄씩 f.readlines()# 한번에 전체 라인 foods = f.readlines()for food in foods : print(food)..
os.path 모듈 파일이나 폴더에 대한 정보를 알수 있는 기능os.path.isdir('c:\\python') #폴더이면 TRUE , 파일이면 False, 폴더없음 Falseos.path.isfile('c:\\python\NEWS.txt') #파일존재 True, 파일아님 False, 파일없음 Falseos.path.exists('c:\\python\abc') #인수의 이름으로 폴더 나 파일이 있으면 Trueos.path.getsize('c:\python\test.txt') #파일의 크기 반환, 폴더는 무조건 4096os.path.split('c:\\python\\news.txt') #('c:\\python', 'NEWS.txt')os.path.splitext('c:\\python\\news.txt') ..