python11

import re
import urllib.request
‘’’
urlretrieve(网址,本地文件存储地址) #直接下载网页到本地
urlcleanup() #清除爬虫缓存
info() #当前爬取 相应的情况
getcode() #
geturl() #
‘’’

urlretrieve(网址,本地文件存储地址) 直接下载网页到本地

data=urllib.request.urlretrieve(“http://www.baidu.com”,“D:/百度网盘/down.html”)
print(data)
‘’’
成功以html下载了
‘’’

#urlcleanup() 直接使用
urllib.request.urlcleanup()

info() 当前爬取 相应的情况,就是简介

file=urllib.request.urlopen(“https://read.douban.com/provider/all”)
print(file.info())
‘’’
Date: Mon, 07 Oct 2019 07:11:41 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 72239
Connection: close

‘’’

getcode() 返回当前网页的状态码 状态码=200(网页正常,可以爬),其他数字都不可以爬

file=urllib.request.urlopen(“https://read.douban.com/provider/all”)
#print(file.info())
print(file.getcode())
‘’’
200
‘’’

geturl() 获取当前爬取页面的url地址

file=urllib.request.urlopen(“https://read.douban.com/provider/all”)
#print(file.info())
#print(file.getcode())
print(file.geturl())
‘’’
https://read.douban.com/provider/all
‘’’

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值