首页 > 编程 > Python > 正文

Python制作CSDN免积分下载器

2020-02-23 00:17:41
字体:
来源:转载
供稿:网友

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))

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表