python html.parser example URL에서 이미지 크롤링
python에서 html parser가 필요해 자료를 찾아보다. 테스트를 겸해 URL에서 이미지 파일을 크롤링하는 코드를 만들어 봤다. python에서 url의 html 가져오기 python의 urllib.request를 사용하면 특정 URL의 html을 쉽게 받아올 수 있다. https://docs.python.org/3.7/library/urllib.request.html#urllib.request.Request import urllib.request with urllib.request.urlopen('https://ryanclaire.blogspot.com') as f: print(f.read(100).decode('utf-8')) python의 html.parser html.parser.HTMLParser는 HTML 및 XHTML 형식의 구문을 분석하기 위해 만들어진 class이다. https://docs.python.org/3.7/library/html.parser.html from html.parser import HTMLParser class MyHTMLParser(HTMLParser): def handle_starttag(self, tag, attrs): print("Encountered a start tag:", tag) def handle_endtag(self, tag): print("Encountered an end tag :", tag) def handle_data(self, data): ...