첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

■ compile 함수를 사용해 웹 페이지의 TITLE 태그에서 제목을 구하는 방법을 보여준다.

 

▶ 예제 코드 (PY)

import urllib.request
import re

httpResponse = urllib.request.urlopen("http://www.example.com")

htmlBytes = httpResponse.read()

httpResponse.close()

html = str(htmlBytes).encode("utf-8").decode("cp949")

pattern = re.compile(r".*?<title.*?>(.*)</title>", re.I | re.S)

list1 = pattern.findall(html)

print(list1)

"""
['Example Domain']
"""
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요