Python makes csdn-free integral downloader _python

Source: Internet
Author: User

CSDN points-free download You know.
1. Enter the resource address, such as: http://download.csdn.net/download/gengqkun/4127808
2.Enter the verification code
3. Click Download and the browser download will pop up.
Note: The success rate is 70-80%. The interface is ugly. Please use it.

Copy the code:

#-*-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
#Set cookies
cookie = http.cookiejar.CookieJar ()
cookieProc = urllib.request.HTTPCookieProcessor (cookie)
opener = urllib.request.build_opener (cookieProc)
urllib.request.install_opener (opener)
#Submit form based on path and POST content
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
#Get verification code picture
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
#Building interface
def createGui (msg = ''):
    global root
    root = tk.Tk ()
    root.title ("CSDN Free Credit Downloader v0.1")
    root.resizable (False, False) #Disable window size modification
    root.geometry ('+ 400 + 250') #screen position
    # -------------------------------------------
    tk_image = getCodeImg ()
    # put the image on a typical widget
    frm_top_label = tk.Label (root, compound = 'top', image = tk_image, text = "captcha image", 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 = "download address:", font = ('Tempus Sans ITC', 15))
    frm_bottom_label_0.grid (row = 0, column = 0, padx = 5, pady = 2, sticky = "e") #Control is right-aligned
    frm_bottom_label_1 = tk.Label (frm_bottom, text = "CAPTCHA:", 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) #Set the password input box, familiar with show
    frm_bottom_entry_1.grid (row = 1, column = 1, padx = 15, pady = 2)
    frm_bottom_btn_0 = tk.Button (frm_bottom, text = "download", 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 ()
#Get download resource address
def getSourceUrl (code, ziyuandz):
    #Resource Information
    strLoginInfo = ('csdn_zh': 'User name',
                    'csdn_mm': 'Password',
                    're_yzm': code,
                    'ziyuandz': ziyuandz # 'http: //download.csdn.net/detail/shinian1987/8430743' #
                    }
    #Download resource address
    urlLogin = 'http: //csdn.juming.com/index.htm'
    returnHtml = str (getUrlRequest (urlLogin, strLoginInfo))
    a = returnHtml.find ('Telecom download address: <strong>') + 15
    b = returnHtml.find ('</ strong> <br> Netcom download address:')
    durl = returnHtml [a: b]
    return durl
#Download resources
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 ('resource address:' + durl)
        reMsg = "A browser is already open, please download ..."
        yzm = durl.find ("Verification Code")
        #yzm + = durl.find ("Verification code verification error")
        #yzm + = durl.find ("The verification code was entered incorrectly")
        fs = durl.find ("Block this tool intentionally")
        gs = durl.find ("correct format like")
        jf = durl.find ("Successfully obtained 0 points")
        xzzy = durl.find ("http:")
        if fs> 0:
            reMsg = "This resource has been blocked, please download it later ..."
        elif code == '':
            reMsg = "The verification code cannot be empty ..."
        elif ziyuandz == '':
            reMsg = "The download address cannot be empty ..."
        elif gs> 0:
            reMsg = "The resource address is incorrect. Please re-enter ..."
        elif yzm> 0:
            reMsg = "The verification code was entered incorrectly ..."
        elif jf> 0:
            reMsg = "Insufficient points to download resources ..."
        elif xzzy> = 0:
            webbrowser.open (durl, new = 0, autoraise = True)
        else:
            reMsg = "Resource error or download resource not found ..."
        #print (xzzy)
        frm_foot_label ['text'] = reMsg
        tk_image = getCodeImg ()
        frm_top_label.configure (image = t
k_image)
         frm_top_label.image = tk_image
     except:
         root.destroy ()
         createGui ('Program error, please download again ...')
#MAIN
createGui ()
Demo picture

 

That's all for this article, I hope everyone will like it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.