urllib2报错,用urllib.request来代替

urllib2报错,用urllib.request来代替

正确代码:

import urllib.request
response=urllib.request.urlopen("http://python.org/")
html=response.read()
#print(len(html))
tokens=[tok for tok in html.split()]
print(tokens[0:100])

注意这里网址一定要用双引号!!!
最后运行正确:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_43582620/article/details/105694088
今日推荐