Python “错误”;未知URL类型:urlopen error";在蟒蛇3中

Python “错误”;未知URL类型:urlopen error";在蟒蛇3中,python,python-3.x,nlp,subprocess,text-mining,Python,Python 3.x,Nlp,Subprocess,Text Mining,这是我的代码,我想从用户输入的URL中提取web的“标题”,但它不起作用 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)

这是我的代码,我想从用户输入的URL中提取web的“标题”,但它不起作用

    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)
重新导入
导入urllib.request
url=输入('请输入网站url:')
h=urllib.request.urlopen(url)
代码=h.read()
pattern=re.compile(r'(.+)',re.M)
title=re.findall(模式、代码)
打印(“%s”标题为:%s”)%(url,标题)
答案必须是这样的:

>>url=raw\u输入('请输入网站url:')
请输入网站网址:http://www.google.com/ 
>>>h=urllib.urlopen(url)>>>code=h.read()
>>>pattern=re.compile(r'(.+)',re.M)
>>>title=re.findall(模式、代码)
>>>打印(“%s”标题为:%s”)%(url,标题)
>>>输出:http://www.google.com/ 标题是:[“谷歌”]

在主题中,它说的是
htttp
,所以看起来你只是在输入测试时通过添加一个额外的
t
键入了
http

Afasn的输出是什么?
>>> 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']