欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Python制作CSDN免积分下载器

程序员文章站 2023-11-23 15:24:58
csdn免积分下载 你懂的。 1、输入资源地址如:http://download.csdn.net/download/gengqkun/4127808 2、输入验证码...

csdn免积分下载 你懂的。
1、输入资源地址如:http://download.csdn.net/download/gengqkun/4127808
2、输入验证码
3、点击下载,会弹出浏览器下载。
注:成功率在70-80% ,界面很丑,请将就着用。

复制代码 代码如下:

#-*-coding:utf-8-*-
#python3.3.5
import urllib.parse,urllib.request,http.cookiejar,io,webbrowser
import tkinter as tk
from tkinter import *
from tkinter.ttk import *
from urllib.request import urlopen
from pil import image, imagetk
global root
#设置cookie 
cookie = http.cookiejar.cookiejar()
cookieproc = urllib.request.httpcookieprocessor(cookie)
opener = urllib.request.build_opener(cookieproc)
urllib.request.install_opener(opener)
#根据路径和post内容来提交表单
def geturlrequest(iurl,istrpostdata):
    postdata = urllib.parse.urlencode(istrpostdata)
    postdata = postdata.encode(encoding='utf8')
    header = {'user-agent':'mozilla/5.0 (compatible; msie 9.0; windows nt 6.1; wow64; trident/5.0)'}
    req= urllib.request.request(
               url = iurl,
               data = postdata,
               headers = header)
    data = urllib.request.urlopen(req).read()
    try:
        data = data.decode('utf-8')
    except:
        data = data.decode('gbk', 'ignore')
    return data
#获取验证码图片
def getcodeimg():
    urlcode='http://csdn.juming.com/code.htm'
    image_bytes = urlopen(urlcode).read()
    # internal data file
    data_stream = io.bytesio(image_bytes)
    # open as a pil image object
    pil_image = image.open(data_stream)
    tk_image = imagetk.photoimage(pil_image)
    return tk_image
#构建界面
def creategui(msg=''):
    global root
    root = tk.tk()
    root.title("csdn免积分下载器 v0.1")
    root.resizable(false, false)   #禁止修改窗口大小
    root.geometry('+400+250')  #屏幕位置
    #-------------------------------------------
    tk_image = getcodeimg()
    # put the image on a typical widget
    frm_top_label = tk.label(root,compound = 'top',image=tk_image,text="验证码图片",fg="blue",bg="brown",font=('tempus sans itc',20))
    frm_top_label.grid(row = 0, column = 0, padx = 15, pady = 2)
    #-------------------------------------------
    frm_bottom = tk.labelframe(root)
    frm_bottom.grid(row = 1, column = 0, padx = 15, pady = 2)
    frm_bottom_label_0 = tk.label(frm_bottom,text="下载地址:", font=('tempus sans itc',15))
    frm_bottom_label_0.grid(row = 0, column = 0, padx = 5, pady = 2,sticky = "e") #控件右对齐
    frm_bottom_label_1 = tk.label(frm_bottom,text="  验证码:", font=('tempus sans itc',15))
    frm_bottom_label_1.grid(row = 1, column = 0, padx = 5, pady = 2,sticky = "e")
    frm_bottom_entry_var_0 = stringvar()
    frm_bottom_entry_0 = tk.entry(frm_bottom,textvariable=frm_bottom_entry_var_0)
    frm_bottom_entry_0.grid(row = 0, column = 1, padx = 15, pady = 2)
    frm_bottom_entry_var_1 = stringvar()
    frm_bottom_entry_1 = tk.entry(frm_bottom,textvariable=frm_bottom_entry_var_1) #设置密码输入框,熟悉show
    frm_bottom_entry_1.grid(row = 1, column = 1, padx = 15, pady = 2)
    frm_bottom_btn_0 = tk.button(frm_bottom,text="下   载",relief=ridge,bd=4,width=10, font=('tempus sans itc',12),command=lambda:downloadsource(frm_bottom_entry_var_0,frm_bottom_entry_var_1,frm_top_label,frm_foot_label))
    frm_bottom_btn_0.grid(row = 3, column = 1, padx = 15, pady = 2,sticky = "w")
    frm_foot_label = tk.label(root,text=msg ,font=('tempus sans itc',10))
    frm_foot_label.grid(row = 3, column = 0, padx = 15, pady = 2)
    root.mainloop() 
#获取下载资源地址  
def getsourceurl(code,ziyuandz):
    #资源信息 
    strlogininfo = {'csdn_zh': '用户名',
                    'csdn_mm': '密码',
                    're_yzm':code,
                    'ziyuandz':ziyuandz #'http://download.csdn.net/detail/shinian1987/8430743' #
                    }
    #下载资源地址
    urllogin='http://csdn.juming.com/index.htm'
    returnhtml = str(geturlrequest(urllogin,strlogininfo))
    a = returnhtml.find('电信下载地址:<strong>') + 15
    b = returnhtml.find('</strong><br>网通下载地址:')
    durl = returnhtml[a:b]
    return durl
#下载资源
def downloadsource(frm_bottom_entry_var_0,frm_bottom_entry_var_1,frm_top_label,frm_foot_label):
    try:
        ziyuandz = frm_bottom_entry_var_0.get()
        code = frm_bottom_entry_var_1.get()
        durl = getsourceurl(code,ziyuandz)
        print('资源地址:'+ durl)
        remsg = "已经打开浏览器,请下载..."
        yzm = durl.find("验证码")
        #yzm += durl.find("验证码验证错误")
        #yzm += durl.find("验证码输入不正确")
        fs = durl.find("封杀本工具特意加")
        gs = durl.find("正确的格式如")
        jf = durl.find("成功获取到0点积分")
        xzzy = durl.find("http:")
        if fs > 0:
            remsg = "该资源被封杀,请稍后再下载..."
        elif code=='':
            remsg = "验证码不能为空..."
        elif ziyuandz=='':
            remsg = "下载地址不能为空..."
        elif gs > 0:
            remsg = "资源地址错误,请重新输入..."
        elif yzm > 0:
            remsg = "验证码输入错误..."
        elif jf > 0:
            remsg = "积分不足,资源无法下载..."
        elif xzzy >= 0: 
            webbrowser.open(durl, new=0, autoraise=true)
        else:
            remsg = "资源错误或没有找到下载资源..."
        #print(xzzy)
        frm_foot_label['text'] = remsg
        tk_image = getcodeimg()
        frm_top_label.configure(image = tk_image)
        frm_top_label.image= tk_image
    except:
        root.destroy()
        creategui('程序错误,请重新下载...')
#main
creategui()

演示图片

Python制作CSDN免积分下载器 

以上就是本文的全部内容了,希望大家能够喜欢。