본문 바로가기
반응형

크롤링4

[파이썬][기초][크롤링]BeautifulSoup 을 이용하여 기상청 스크래핑 BeautifulSoup 을 이용하여 기상청 스크래핑 ㅁ 필수 설치 패키지 1) BeautifulSoup 설치 - 명령어 : pip3 install BeautifulSoup ㅁ 소스코드 - 복사해서 실행 가능합니다. # 라이브러리 읽기 from bs4 import BeautifulSoup import urllib.request as req # 기상청 URL url = 'http://www.kma.go.kr/weather/forecast/mid-term-rss3.jsp' # URL OPEN으로 데이터 가져오기 res = req.urlopen(url) #beautifulsoup 으로 분석 soup = BeautifulSoup(res, 'html.parser') #원하는 데이터 추출 title = soup.f.. 2018. 10. 26.
[파이썬][기초][크롤링]HTML 구조-"find_all()"를 이용한 데이터 스크래핑 [파이썬][기초][크롤링]HTML 구조-"find_all()"를 이용한 데이터 스크래핑 예제 ㅁ 필수 설치 패키지 1) BeautifulSoup 설치 - 명령어 : pip3 install BeautifulSoup ㅁ 소스코드 - 복사해서 실행 가능합니다. # 라이브러리 읽기 from bs4 import BeautifulSoup # 분석하고 싶은 HTML html = """ naver daum """ #html 분석하기 soup = BeautifulSoup(html, 'html.parser') #find_all() 메서드로 원하는 부분 추출하기 links = soup.find_all("a") #출력 for a in links: href = a.attrs['href'] text = a.string print.. 2018. 10. 26.
[파이썬][기초][크롤링]HTML 구조-"id요소"를 이용한 데이터 스크래핑 BeautifulSoup 을 이용하여 HTML의 id요소 정보를 통해 스크래핑 하는 예제 ㅁ 필수 설치 패키지 1) BeautifulSoup 설치 - 명령어 : pip3 install BeautifulSoup ㅁ 소스코드 - 복사해서 실행 가능합니다.# 라이브러리 읽기from bs4 import BeautifulSoup # 분석하고 싶은 HTMLhtml = """웹 페이지를 분석하는것웹 페이지를 추하는것""" #html 분석하기soup = BeautifulSoup(html, 'html.parser') #find() 메서드로 원하는 부분 추출하기title = soup.find("h1")body = soup.find("body") #출력print(title)print(body) ㅁ 실행결과 - 실행방법 : .. 2018. 10. 26.
[파이썬][기초][크롤링]HTML 구조-"태그"를 이용한 데이터 스크래핑 BeautifulSoup 을 이용하여 HTML의 태그정보를 통해 스크래핑 하는 예제 ㅁ 필수 설치 패키지 1) BeautifulSoup 설치 - 명령어 : pip3 install BeautifulSoup ㅁ 소스코드 - 복사해서 실행 가능합니다.# 라이브러리 읽기from bs4 import BeautifulSoup # 분석하고 싶은 HTMLhtml = """웹 페이지를 분석하는것웹 페이지를 추하는것""" #html 분석하기soup = BeautifulSoup(html, 'html.parser') #원하는 부분 추출h1 = soup.html.body.h1p1 = soup.html.body.pp2 = p1.next_sibling.next_sibling# 위 소스의 next_sibling_next 는 HTML.. 2018. 10. 26.