使用
httpget.py
#!usr/bin/evn python3
# -*- coding: utf-8 -*-
# 引用库,Python3使用urllib.request
import urllib.request
# ----Get请求
url = 'http://www.baidu.com'
# response = urllib.request.urlopen(url)
# 带头的请求, 需要构造Reqeust对象来设置
request = urllib.request.Request(url, headers = {'User-Agent' : 'Python3/xzm'})
response = urllib.request.urlopen(request)
# 返回数据是utf-8编码,进行转码。Python的字符串是使用unicode编码
print(response.read().decode('utf-8'))
python httpget.py
参考文章:
python3网络爬虫一《使用urllib.request发送请求》
https://blog.csdn.net/bo_mask/article/details/76067790