南归 发表于 2021-5-20 10:45:06

多线程下载头像

本帖最后由 南归 于 2021-5-20 10:57 编辑

来论坛这么久了还没发过正经的帖子,把练手的多线程代码发一下,请大家指教

win10测试可用,运行后在电脑桌面会生成一个txpic文件夹

# V1.0
"""
文件   :pic_down.py
时间   :2021/02/02 20:54:39
"""

import requests
import re
import os
import winreg
import threading
import queue


headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36"
}


def get_directory():# 判断路径是否存在,否的话生成
    global path
    key = winreg.OpenKey(
      winreg.HKEY_CURRENT_USER,
      r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders",
    )
    path = winreg.QueryValueEx(key, "Desktop") + "\\txpic\\\"
    print(path)
    if not os.path.exists(path):
      os.mkdir(path)


def pic_down(url):
    # 动漫

    first_response = requests.get(url=url, headers=headers)
    pic_urllist = re.findall(r'"thumb": "(.*?)",', first_response.text)
    id_list = re.findall(
      r"http://img6.dl.ltimg.net/(.*?)\?auth_key=", first_response.text
    )
    name_dict = dict(zip(pic_urllist, id_list))
    for pic_url in pic_urllist:
      final_response = requests.get(url=pic_url, headers=headers)
      name = name_dict
      with open(path + name + ".jpg", "wb") as f:
            f.write(final_response.content)
    # return pic_url


if __name__ == "__main__":
    get_directory()
    q = queue.Queue()
    for i in range(1, 100):# 构造网站队列
      url = r"http://service.picasso.adesk.com/v1/avatar/avatar?limit=30&skip={}&adult=false&first=0&order=time".format(
            i * 30
      )
      q.put(url)
    while not q.empty():
      for i in range(5):
            try:
                t = threading.Thread(
                  target=pic_down, args=(q.get(block=False),)
                )# ! 堵塞?
                t.start()
            except:# *未知错误
                pass

https://www.hualigs.cn/image/60a5ccfdde92c.jpg

南归 发表于 2021-5-20 16:07:45

太冷清了吧

TooBeautiful 发表于 2021-5-28 05:20:32

本帖最后由 TooBeautiful 于 2021-5-28 05:40 编辑

楼主美美哒!!!,你的这个是服务器地址啊!!!,微信小程序

南归 发表于 2021-5-28 09:55:06

TooBeautiful 发表于 2021-5-28 05:20
楼主美美哒!!!,你的这个是服务器地址啊!!!,微信小程序

??什么服务器地址

全能小乌贼 发表于 2021-5-28 18:30:05

目测楼主的头像是网图吧

TooBeautiful 发表于 2021-5-29 10:53:56

南归 发表于 2021-5-28 09:55
??什么服务器地址

你的api的,我打开后直接是一个字典。才疏学浅,学艺不精!!!


南归 发表于 2021-5-31 19:00:01

全能小乌贼 发表于 2021-5-28 18:30
目测楼主的头像是网图吧

那不是鞠婧祎吗....

南归 发表于 2021-5-31 19:00:57

TooBeautiful 发表于 2021-5-29 10:53
你的api的,我打开后直接是一个字典。才疏学浅,学艺不精!!!

对啊,抓包得到的

全能小乌贼 发表于 2021-7-16 12:30:19

南归 发表于 2021-5-31 19:00
那不是鞠婧祎吗....

哈哈哈哈,好吧

编程追风梦 发表于 2022-3-7 06:43:14

我服了,你就写成这样,还想批评我,你就是下载字典而已

编程追风梦 发表于 2022-3-7 06:44:05

下载头像,成了字典,我服了,我那个文章是一行代码破解wifi,你这是什么?还说我没有技术含量!

编程追风梦 发表于 2022-3-7 06:45:26

https://fishc.com.cn/thread-209849-1-1.html

编程追风梦 发表于 2022-3-7 06:46:14

这个链接,自己看你说的什么

编程追风梦 发表于 2022-3-7 06:47:52

你这是什么语言啊,python?行了,我现在玩51单片机,这就是为什么我来这里学C语言,python早就学过

编程追风梦 发表于 2022-3-7 06:49:49

一点技术含量都木有,有本事你去破解网络
页: [1]
查看完整版本: 多线程下载头像