-2
이것은 내 코드입니다. 사용자가 입력 한 URL에서 웹의 '제목'을 추출하려고하지만 작동하지 않습니다.python3에서 "알 수없는 URL 유형 : urlopen 오류"
import re
import urllib.request
url = input('Please enter website URL : ')
h = urllib.request.urlopen(url)
code = h.read()
pattern = re.compile(r'<title>(.+)</title>', re.M)
title = re.findall(pattern, code)
print("%s title is : %s") % (url, title)
대답은 다음과 같이해야합니다 : 피사체에서
>>> url = raw_input('Please enter website URL : ')
Please enter website URL : http://www.google.com/
>>> h = urllib.urlopen(url) >>> code = h.read()
>>> pattern = re.compile(r'<title>(.+)</title>', re.M)
>>> title = re.findall(pattern, code)
>>> print("%s title is : %s") % (url, title)
>>>output: http://www.google.com/ title is : ['Google']
출력 Afasn이란 무엇입니까? –