手把手教你爬取 小姐姐视频

import os
import requests
import time
import random
import string


def download_video(url):
    response = requests.get(url)
    data = response.content
    paths = time.strftime("%Y-%m-%d", time.localtime())
    if data:
        try:
            savePath = os.getcwd() + '/' + paths
            if not os.path.exists(savePath):   # 判断目标路径下是否包含目标文件夹
                os.makedirs(savePath)     # 没有则新建该文件夹
            file_path = '{}/{}.{}'.format(savePath, ran(), 'mp4')
            if not os.path.exists(file_path):
                with open(file_path, 'wb') as f:
                    f.write(data)
                    f.close()
        except Exception:
            print('处理错误跳过')


# 生成随机8位文件名
def ran():
    salt = ''.join(random.sample(string.ascii_letters + string.digits, 8))  # 随机输出8位由英文字符和数字组成的字符串
    return salt


if __name__ == "__main__":
    i = 1
    while True:
        url = requests.get("http://********哈哈坏不坏.com/get.php").text
        download_video(url)
        index = random.randint(3, 5)
        i = (i+1)
        print('处理完成第' + str(i) + '个视频')
        time.sleep(index)

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值