Python creates a CSDN point-Free Download device and pythoncsdn
Download CSDN without points, you know.
1. Enter the resource address such as: http://download.csdn.net/download/gengqkun/4127808
2. Enter the verification code
3. Click Download. the browser will pop up for download.
Note: The success rate is between 70 and 80%, and the interface is ugly. Please try again.
Copy codeThe Code is as follows:
#-*-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
# Setting cookies
Cookie = http. cookiejar. CookieJar ()
CookieProc = urllib. request. HTTPCookieProcessor (cookie)
Opener = urllib. request. build_opener (cookieProc)
Urllib. request. install_opener (opener)
# Submit a form based on the 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 t:
Data = data. decode ('gbk', 'ignore ')
Return data
# Retrieving Verification Code Images
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
# Build an Interface
Def createGui (msg = ''):
Global root
Root = tk. Tk ()
Root. title ("CSDN point-free download server 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 = "Verification Code 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 = ":", font = ('Tempus Sans itc', 15 ))
Frm_bottom_label_0.grid (row = 0, column = 0, padx = 5, pady = 2, sticky = "e") # Right-aligned Control
Frm_bottom_label_1 = tk. Label (frm_bottom, text = "Verification Code:", 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 = "downlink", 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 ()
# Obtain the download resource address
Def getSourceUrl (code, ziyuandz ):
# Resource Information
StrLoginInfo = {'csdn _ zh ': 'username ',
'Sdn _ 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: <strong> ') + 15
B = returnHtml. find ('</strong> <br> Netcom :')
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 = "the browser has been opened. Please download ..."
Yzm = durl. find ("Verification Code ")
# Yzm + = durl. find ("Verification code verification error ")
# Yzm + = durl. find ("Incorrect verification code input ")
Fs = durl. find ("block this tool specially added ")
Gs = durl. find ("the correct format is as follows ")
Jf = durl. find ("0 points obtained successfully ")
Xforwardedurl. find ("http :")
If fs> 0:
ReMsg = "this resource is blocked. Please download it later ..."
Elif code = '':
ReMsg = "The Verification Code cannot be blank ..."
Elif ziyuandz = '':
ReMsg = "cannot be blank ..."
Elif gs> 0:
ReMsg = "The resource address is incorrect. Please enter another address ..."
Elif yzm> 0:
ReMsg = "Incorrect verification code input ..."
Elif jf> 0:
ReMsg = "insufficient credits, resources cannot be downloaded ..."
Elif xif> = 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 = tk_image)
Frm_top_label.image = tk_image
Except t:
Root. destroy ()
CreateGui ('program error, please download again ...')
# MAIN
CreateGui ()
Demo Image
The above is all the content of this article. I hope you will like it.