2017-05-04 5 views
-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'] 
+0

출력 Afasn이란 무엇입니까? –

답변

2

는 사용자가 입력 할 때 그냥 여분의 t을 추가하여 http을 typo'ed 것 같습니다, 그래서 htttp을 말한다 그것은 테스트합니다.