您的位置:首页 > 编程语言 > Python开发

Python3 的urllib库

2016-07-14 00:00 295 查看
摘要: Python 3.x中urllib库和urilib2库合并成了urllib库, 用于抓取网页的数据。

方法一:

import urllib.request

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

方法二:

import urllib.request

req = urllib.request.Request("http://www.baidu.com")
response = urllib.request.urlopen(req)
html_data = response.read()
print(html_data)

建议使用方法二,可以加入必要请求参数(url, data。。。)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: