Python爬虫:1_爬取一个网页
作者:互联网
from urllib.request import urlopen
url = 'http://www.baidu.com'
resp = urlopen(url)
with open('mybaidu.html', mode='wb') as f:
f.write(resp.read())
print('over')
urllib:该库可操作URL
urllib.request:打开/读取url
urllib.error:有urllib.request抛出的异常
urllib.parse:解析URL
urllib.robotparse:解析robots.txt文件
urlopen(url):打开url地址
mybaidu.html效果
标签:Python,resp,URL,request,爬虫,urllib,爬取,url,urlopen 来源: https://blog.csdn.net/weixin_45743734/article/details/122330569