import urllib.request
file=urllib.request.urlopen("http://www.baidu.com")
print(file.read().decode())
得到如下信息
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta content="always" name="referrer">
<meta name="theme-color" content="#2932e1">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
<link rel="search" type="application/opensearchdescription+xml" href="/content-search.xml" title="百度搜索" />
<link rel="icon" sizes="any" mask href="//www.baidu.com/img/baidu_85beaf5496f291521eb75ba38eacbd87.svg">
import urllib.request
file=urllib.request.urlopen("http://www.taobao.com")
# print(file.read().decode())
print(file.read().decode("gbk"))