首页 > 其他 > 详细

3GPP协议下载 #requests/bs4/threading

时间:2021-02-07 18:09:29      阅读:19      评论:0      收藏:0      [点我收藏+]
import requests
from bs4 import BeautifulSoup
import threading

# 线程锁
thread_lock = threading.BoundedSemaphore(value=10)


def get_3gppurl():
    urllist = []
    url = https://www.3gpp.org/ftp/Specs/archive/38_series/

    response = requests.get(url).content.decode(utf-8)

    bs = BeautifulSoup(response, html.parser).find(tbody).find_all(a)

    for b in bs:
        u = b[href]
        urllist.append(u)
    return urllist


def download_zip(u, t):
    res = requests.get(u)
    path = ./3gpp-TS38.xx/ + str(t)
    with open(path, wb+) as file:
        file.write(res.content)
    # 解锁
    thread_lock.release()


def get_zip(url1):
    response = requests.get(url1).content.decode(utf-8)

    bs = BeautifulSoup(response, html.parser).find(tbody).find_all(a)
    for b in bs:
        u = b[href]
        t = b.text
        print(u, t)
        # 上锁,
        thread_lock.acquire()
        t = threading.Thread(target=download_zip, args=(u, t))
        t.start()


if __name__ == __main__:
    urllist = get_3gppurl()
    for url1 in urllist:
        print(url1)
        get_zip(url1)

# 打印结果

技术分享图片

 

# 下载结果

技术分享图片

 

3GPP协议下载 #requests/bs4/threading

原文:https://www.cnblogs.com/zxzxq/p/14384537.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!