同学吹水,提到了爬虫,于是金工实习回来晚上看了看爬虫
(话说为啥所有爬虫教程前面都是一大串python基础教程啊)
import urllib.request
#1、定义一个网址url
url='http://www.baidu.com'
#2、模拟浏览器向服务器发送请求
response = urllib.request.urlopen(url)
print(type(response))
#一个字节一个字节读入
# content = response.read()
#读取括号内个字节的字符
# content = response.read(5)
#一行读取
# content = response.readline()
#一行一行读取,直到最后
# content = response.readlines()
#获得html状态码
# print(response.getcode())
#获得地址
# print(response.geturl())
#获得headers
print(response.getheaders())
标签:初体验,python,爬虫,content,url,print,response
From: https://www.cnblogs.com/ajmddzp/p/17536237.html