Last active
July 5, 2024 13:30
-
-
Save muzizongheng/6019506 to your computer and use it in GitHub Desktop.
login CSDN by using urllib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Use this utility to access CSDN blog. | |
#Author: jiangong li | |
#Email: Jgli_2008@sina.com | |
import base64 | |
from http import cookiejar | |
import urllib.request, urllib.parse, urllib.error | |
#url for accessing | |
csdnLoginUrl = r"http://passport.csdn.net/ajax/accounthandler.ashx?" | |
moduleUrl = r"http://write.blog.csdn.net/postedit/" | |
csdnAccessModuleUrl = r"http://passport.csdn.net/account/loginbox?callback=logined&hidethird=1&from="+urllib.parse.quote(moduleUrl)#http%3a%2f%2fwrite.blog.csdn.net%2f" | |
#install cookie | |
cj = cookiejar.CookieJar(); | |
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj)); | |
urllib.request.install_opener(opener) | |
#build request for accessed url | |
homeReq = urllib.request.Request( | |
url = csdnAccessModuleUrl | |
) | |
homeReq.add_header('Accept', 'text/html, application/xhtml+xml, */*'); | |
homeReq.add_header('Accept-Language', 'en-US') | |
homeReq.add_header('Accept-Encoding', 'gzip, deflate') | |
homeReq.add_header('Connection', 'Keep-Alive'); | |
homeReq.add_header('Referer', 'http://passport.csdn.net/account/login?from='+urllib.parse.quote(moduleUrl))#http%3a%2f%2fwrite.blog.csdn.net%2f') | |
homeReq.add_header('User-Agent', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)'); | |
#open access url | |
resp = urllib.request.urlopen(homeReq) | |
print(resp.info()) | |
print(resp.status) | |
print(cj) | |
################################################################################ | |
#build request for login url | |
#post data | |
postdata = { | |
'u':'yourUserName', | |
'p':'yourPassword', | |
'remember':'1', | |
't':'log', | |
'f':urllib.parse.quote(moduleUrl), | |
} | |
postdata = urllib.parse.urlencode(postdata).encode('utf-8') | |
print(postdata) | |
req = urllib.request.Request( | |
url = csdnLoginUrl, | |
data = postdata) | |
req.add_header('Accept', 'text/html, application/xhtml+xml, */*'); | |
req.add_header('Accept-Language', 'en-US') | |
req.add_header('Accept-Encoding', 'gzip, deflate') | |
req.add_header('Connection', 'Keep-Alive'); | |
req.add_header('Referer', csdnAccessModuleUrl) | |
req.add_header('User-Agent', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)'); | |
#open login url | |
r = urllib.request.urlopen(req) | |
print(r.status) | |
print(r.reason) | |
print(r.geturl()) | |
print(r.info()) | |
data = r.read().decode('utf-8') | |
print(data) | |
print(cj) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tried in 2k24 and doesn't work.
Just go to Quackr.io FRANCE Section (make sure to make an account cuz France numbers require it). Don't try other countries as they will fail or the message won't ever come in.
Then go to CSDN Login and in the third tab put a phone number that you got from Quackr.io and send a verification code.
You are now registered.
Please leave a like and a follow to make my day better :)