f1 = open('wen.txt','r')
print(f1.read(3))
# 文件指针用于表明文件读取的其实位置, 文件指针表明了文件将要从那个位置开始读写
#tell() 函数 返回文件指针的位置
print(f1.tell())
'''
seek() 函数用于将文件的指针移动到指定的位置
'''
'''
split() 函数
'''
str1 = open('wen.txt')
print(str1.read())
str1.seek(0)
print(str1.tell())
str2 = "hell boy<[www.bai.=du.com]byebye>"
print(str2.split('[')[1].split([']'][0]))
f2 = open('wenjian1.txt')
with open('wenjian1.txt','r',encoding='utf-8') as f:
m = f.readlines()
for i in m:
print(i)
请求超时
import requests
# 循环发送请求50次
for a in range(50):
try:
response = requests.get('https://www.baidu.com/', timeout=0.1)
print(response.status_code)
except Exception as e:
print('异常'+str(e))
import requests
# 导入request.exceptions 模块类的3种异类
from requests.exceptions import ReadTimeout,HTTPError,RequestException
# 循环发送请求50次
for a in range(50):
try:
response = requests.get('https://www.baidu.com/', timeout=0.1)
print(response.status_code)
except ReadTimeout:
print('timeout, 请求超时')
except HTTPError:
print('httperror, HTTP异常')
except RequestException:
print('reqerror, 请求异常')