38 lines
970 B
Python
38 lines
970 B
Python
import requests
|
|
import os
|
|
|
|
#
|
|
# # 京东页面商品爬取案例
|
|
# def get_JD_text():
|
|
# kv = {'User-agent': 'Mozilla/5.0'}
|
|
# try:
|
|
# r = requests.get(url,headers=kv)
|
|
# r.raise_for_status()
|
|
# r.encoding = r.apparent_encoding
|
|
# return r.text
|
|
# except:
|
|
# print("产生异常")
|
|
#
|
|
#
|
|
# if __name__ == "__main__":
|
|
# url = "https://item.jd.com/12842874.html"
|
|
# print(get_JD_text())
|
|
|
|
|
|
url = 'https://player.youku.com/embed/XNTY2MTQ0MDgw'
|
|
root = "D://program//"
|
|
path = root + url.split('/')[-1]+'.mp4'
|
|
try:
|
|
if not os.path.exists(root):
|
|
os.mkdir(root) # 判断文件根目录是否存在,如果不存在创建根目录
|
|
if not os.path.exists(path): # 判断文件是否存在
|
|
r = requests.get(url)
|
|
with open(path, 'wb') as f:
|
|
f.write(r.content)
|
|
f.close()
|
|
print("文件保存成功")
|
|
else:
|
|
print("文件已存在")
|
|
except:
|
|
print("出现异常")
|