본문 바로가기

goorm.io

(4)
[PYTHON] 파이썬 예제 뽀개기 텍스트의 첫 단어 출력 def first_word(): word = input() A = word.replace(".", " ") and word.replace("," , " ") A = word.split() print(A[0]) first_word()
[PYTHON] 기본 함수 1. 문장이 ~~로 끝나는지 확인 → .endswith() # Python code shows the working of # .endswith() function text = "geeks for geeks." # returns False result = text.endswith('for geeks') print (result) # returns True result = text.endswith('geeks.') print (result) # returns True result = text.endswith('for geeks.') print (result) # returns True result = text.endswith('geeks for geeks.') print (result) 2. A값을 B값으로..
[PYTHON] Beautiful soup [HTML과 XML 파일로부터 원하는 데이터를 추출하는 크롤링 라이브러리] from bs4 import BeautifulSoup from urllib.request import urlopen with urlopen('https://en.wikipedia.org/wiki/Main_Page') as response: soup = BeautifulSoup(response, 'html.parser') for anchor in soup.find_all('a'): print(anchor.get('href', '/')) ○ html 내 타이틀, 바디, url, 텍스트 등 필요로 하는 부분만 뽑아서 정렬 가능. ex) 다음사이트의 인기검색어 추출하기 for A in soup.select("div.slide_favors..
[PYTHON] 생활코딩 복습 : 1번째 : 2번째 : 3번째 ######################################################true, false = 불리언 print('Hello ' + 'world') print('Hello ' * 3) print('Hello' [0]) print('Hello' [1]) print('Hello' [2]) print('hello world'.capitalize()) print('hello world'.upper()) print('hello world'.__len__()) print(len('hello world')) print('Hello world'.replace('world', 'programming')) print("goorm's \"tutorial\"") pr..