Python day_03

 

# Built-in module

# Module package
related to reptiles #

 

Built-in module

'''
time
json
the
sys

'' ' 
# # Time 
# Import time introducing time module # 
# # obtain a timestamp 
# Print (the time.time ())
#
# # Wait two seconds 
# the time.sleep (2) 
# Print (time.time ())

# # OS 
# Import OS 
# # determines whether the current path tank.txt 
# Print (os.path.exists ( 'tank.txt')) #False 
# Print (os.path.exists (r'D: \ pyproject \ day03 \ users.txt ')) # True
#
# # Gets the root directory of the current file 
# Print (os.path.dirname (__ file__))

# # SYS 
# Import SYS 
# # python get file path environment variable 
# Print (sys.path) 
# sys.path.append (os.path.dirname (__ file__)) 
# Print (sys.path)

# Dumps: sequence of 
# 1, the switch to a string dictionary 
# 2, then the data is converted into a string json 
# RES = json.dumps (USER_INFO) 
# Print (RES) 
# Print (type (RES))

# # Loads: deserialize 
# # json.loads () 
# #. 1, the data files into memory json 
# with Open ( 'user.json', 'R & lt', encoding = 'UTF-. 8') AS F: 
#      # reading obtained string 
#      RES reached, f.read = () 
#      # Print (type (RES)) 
#      #loads converted into the format string json type dict 
#      user_dict = json.loads (RES) 
#      Print (user_dict) = json.loads (RES) 
#      Print (type (user_dict)) # <class 'dict'>
#
# # dump
# user info = {}
#     'name': 'tank',
#     'pwd': '123'
# }
# with open('user_info.json', 'w', encoding='utf-8') as f:
#     # str1 = json.dumps(user_info)
#     # f.write(str1)
#     # json.dump(user_info, f)

 

02, module and pack import + module name

# Import module name 
Import B

# From 
# import a file module B 
# automatically performs a file code 
from B Import a

# __name__: B.a
# a

 

Reptile related to video, for example baidu.com and pears

''''''
'''
http协议:
    请求url:
        https://www.baidu.com/
        
    请求方式:
        GET
        
    请求头:
        Cookie: 可能需要关注。
        User-Agent: 用来证明你是浏览器
            注意: 去浏览器的request headers中查找
            Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36
        Host: www.baidu.com
'''

# requests模块使用
# pip3 install requests
# pip3 install -i 清华源地址 模块名
# pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple requests

# import requests
#
# response = requests.get(url='https://www.baidu.com/')
# response.encoding = 'utf-8'
# print(response)  # <Response [200]>
# # 返回响应状态码
# print(response.status_code)  # 200
# # 返回响应文本
# # print(response.text)
# print(type(response.text))  # <class 'str'>
#
# with open('baidu.html', 'w', encoding='utf-8') as f:
#     f.write(response.text)



# 爬取梨视频
# 爬取视频界面
import requests
res = requests.get('https://video.pearvideo.com/mp4/adshort/20190613/cont-1565852-14013295_adpkg-ad_hd.mp4')

print(res.content)
with open('vodio.mp4', 'wb') as f:
f.write(res.content)
 

 

Guess you like

Origin www.cnblogs.com/moxianyinzou/p/11022688.html