웹(web)/크롤링(web scraping)
-
코로나확진자 웹사이트 최근 업데이트 시간 크롤링(worldometers.info/coronavirus)웹(web)/크롤링(web scraping) 2020. 5. 3. 14:36
코로나 확진자 수를 가져오는 여러 가지 방법이 있다. 뉴스를 통해 확인하는 방법, 특정 사이트에 가서 가져오는 방법 등이 있을 것이다. 이번 글은 www.worldometers.info 에서 제공하는 coronavirus 정보가 언제 업데이트되었는지 그 시간을 가져오는 코드를 작성해 보려고 한다. 방법은 간단하다. 사이트를 분석해서 어떻게 정보를 가져올지 분석한 후 파이썬을 이용해서 크롤링 코드를 작성하면 된다. 사이트 분석은 크롬의 개발자 도구를 이용하며 파이썬 개발환경은 구글의 코랩을 이용하면 빠르게 개발할 수 있다. 사이트 분석은 정적인 웹사이트인지 아니면 동적인 웹사이트인지 구분하고 그에 따라 사용하는 도구를 바꾸면 크롤링이 완료된다. 이번 예시를 통해서 그림을 그려보도록 하자. 아래 사진은 사이..
-
regex training site웹(web)/크롤링(web scraping) 2019. 7. 7. 00:08
https://regexone.com/ RegexOne - Learn Regular Expressions - Lesson 1: An Introduction, and the ABCs Regular expressions are extremely useful in extracting information from text such as code, log files, spreadsheets, or even documents. And while there is a lot of theory behind formal languages, the following lessons and examples will explore the more prac regexone.com Lesson 파트를 본 후 Problem 파트를 ..
-
crawl_sitemap() with re.findall()웹(web)/크롤링(web scraping) 2019. 7. 6. 18:21
요청한 url html에서 사이의 값들이 얻어진다. 이를 가지고 다시 request를 요청하는 내용이다. + download() 를 보완 code: import urllib.request from urllib.error import URLError, HTTPError, ContentTooShortError import re def download(url, user_agent='wswp', num_retries=2, charset='utf-8'): print('Downloading:',url) request = urllib.request.Request(url) request.add_header('User-agent',user_agent) try: resp = urllib.request.urlopen(req..
-
download() with num_tries웹(web)/크롤링(web scraping) 2019. 7. 6. 17:17
request의 반환값에 따라 작동방식을 다르게 한 코드 code: import urllib.request from urllib.error import URLError, HTTPError, ContentTooShortError def download(url, num_retries=2): print('Downloading:', url) try: html = urllib.request.urlopen(url).read() except (URLError, HTTPError, ContentTooShortError) as e: print('Download error:', e.reason) html = None if num_retries > 0: if hasattr(e,'code') and 500
-