python urllib学习

·什么是urllib:

Python内置的html请求库(不需要安装的库)

urllib.request 请求模块

urllib.error 异常处理模块

urllib.parse url解析模块

urllib.tobotparse robot.txt解析模块

python2的变化:

python2:

import urllib2

response =urllib.urlopen('http://www.baidu.com')

python3

import request.urllib

response = request.urllib.urlopen('http://www.baidu.com')

urllib用法详细

·urlopen

基本用法:urllib.request.urlopen(url(后面可加参数,但是用的少))

import urllib.request

response = urllib.request.urlopen("http://www.baidu.com")

print(response.read().decode('utf-8')) read()获取网页的代码,decode()指定编码格式

猜你喜欢

转载自blog.csdn.net/qq_41983562/article/details/84179442